-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
335 lines (247 loc) · 8.22 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
require_once('functions_all.php');
//record that user has logged out
$Page->make_Header();
if(!empty($_SESSION['isListing']) && $_SESSION['isListing'] == 1)
{
unset($_SESSION['isListing']);
unset($_SESSION['gender1']);
unset($_SESSION['gender2']);
unset($_SESSION['age']);
unset($_SESSION['description']);
}
?>
<script>
var socket = io.connect('http://dppchat.jit.su:80');
//var socket = io.connect('http://localhost:8080');
// setInterval (update_roomcount, 120000); //Checks every 120 seconds to update number of room
//this submits the registration form
$(document).ready(function(){
//register form event
$("#registerform").submit(function(event){
event.preventDefault();
var username = $('#r_username').val();
var password1 = $('#r_password1').val();
var password2 = $('#r_password2').val();
var dob_month = $('#r_dob_month').val();
var dob_day = $('#r_dob_day').val();
var dob_year = $('#r_dob_year').val();
var gender = $('#r_gender').val();
if(username == 'host' || username == 'guest' || username == 'default')
{
alert("This username is reserved");
return;
}
//check if valid username
if(!usernameIsValid(username) || username.length < 3 || username.length > 20)
{
alert('Error: Usernames may only contain letters, numbers, underscore and hyphen and must between 3-20 characters');
return;
}
//check if passwords match
if(password1 != password2)
{
alert('Error: Passwords do not match');
return;
}
//check if passwords match
if(password1 < 5 || password1 > 20)
{
alert('Error: Passwords must contain 5 to 20 characters');
return;
}
var date = dob_day + '/' + dob_month + '/' + dob_year;
//check if valid date
if(!isValidDate(date))
{
alert('Error: Invalid date of birth');
return;
}
//check if valid month and user over 18
var date1 = new Date();
var date2 = new Date(dob_month + ', ' + dob_day + ', ' + dob_year);
var trueday = date1.getDate();
var truemonth = date1.getMonth() + 1;
var yearDiff = date1.getFullYear() - date2.getFullYear() - 1;
if((dob_month < truemonth) || (dob_month == truemonth && dob_day <= trueday))
{ yearDiff++; }
if(yearDiff < 18)
{
alert('Error: You must be 18 years of age or older to use this service');
return;
}
//check if valid gender
if(gender != 'm' && gender != 'f')
{
alert('Error: Invalid Gender');
return;
}
//pack everything into an object and send in to be registered... kick back any errors. on success, set session and forward!
var registrationdata = {};
registrationdata.username = username;
registrationdata.password = password1;
registrationdata.dob_day = dob_day;
registrationdata.dob_month = dob_month;
registrationdata.dob_year = dob_year;
registrationdata.gender = gender;
socket.emit("register", registrationdata, function(response){
if(response == true)
{
$.getJSON("script_login.php", { username: username, password: password1 }, function(data){
if(data.result == true)
{
window.location = "home.php";
return;
}
else
{
alert(data);
return;
}
});
}
else
{
alert(response);
return;
}
});
});
//login form event
$("#loginform").live('submit', function(event){
event.preventDefault();
var username = $('#l_username').val();
var password = $('#l_password').val();
if(username == null || password == null)
{
alert("Username and Password fields cannot be null");
return;
}
var logindata = {};
logindata.username = username;
logindata.password = password;
logindata.loginlevel = 1;
socket.emit("login", logindata, function(response){
if(response == true)
{
$.getJSON("script_login.php", { username: username, password: password }, function(data){
if(data.result == true)
{
window.location = "home.php";
return;
}
else
{
alert(data);
return;
}
});
}
else
{
alert(response);
return;
}
});
});
});
//helper functions
function usernameIsValid(username) {
return /^[0-9a-zA-Z_-]+$/.test(username);
}
function isValidDate(s) {
var bits = s.split('/');
var d = new Date(bits[2], bits[1] - 1, bits[0]);
return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]);
}
</script>
<?php $Page->display_messages(); ?>
<!--<div class="redhat">
<b>Error!</b> Chat servers are temporarily down.</a>
</div>
<br class="clear">--->
<div class="col-1" style="min-height: 100px">
<div class="login">
<h2>Register (For New Users)</h2><hr>
<form id="registerform">
<div class="A1">Username:</div>
<div class="A2 t-right"><input type="text" id="r_username" class="input"></div>
<div class="A1">Password:</div>
<div class="A2 t-right"><input type="password" id="r_password1" class="input"></div>
<div class="A1">Confirm Password:</div>
<div class="A2 t-right"><input type="password" id="r_password2" class="input"></div>
<div class="A1">Date of Birth:</div>
<div class="A2 t-right">
<select id="r_dob_month" style="width: 51px;" class="select">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select id="r_dob_day" style="width: 42px;" class="select">
<?php
for($i = 1; $i <= 31; $i++)
{ echo '<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
<select id="r_dob_year" style="width: 59px;" class="select">
<?php
$date = date('Y');
for($i = 1; $i <= 100; $i++)
{
$display = $date - $i;
echo '<option value="'.$display.'">'.$display.'</option>';
}
?>
</select>
</div>
<div class="A1">Gender:</div>
<div class="A2 t-right">
<select style="width: 160px;" id="r_gender" class="select">
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</div>
<div class="A3 t-right"><button class="button">Submit</button></div>
</form>
<br class="clear"><br>
<h2>Terms of Service</h2><hr>
<b>1)</b> This service may not be used for any illegal activity.<br>
<b>2)</b> By using this service, you agree not to use bots, scripts or other similar
software to interact in any way with the site.<br>
<b>3)</b> By using this service, you agree not to post any content that may
be viewed by a reasonable person as spam.<br>
<b>4)</b> By using this serivce, you agree not to do harm to our servers or to the content
of our servers<br>
<b>5)</b> By using this serivce, you agree to accept any harm done to your computer system<br>
<b>6)</b> Terms of service may change at any time without notification.<br>
<br clear="clear"><br>
</div><!--end of col1-->
</div>
<div class="col-2" style="min-height: 100px">
<span class="login">
<form id="loginform">
<h2>Login</h2><hr>
<div class="A1">Username:</div>
<div class="A2 t-right"><input type="text" class="input" id="l_username"></div>
<br class="clear">
<div class="A1">Password:</div>
<div class="A2 t-right"><input type="password" class="input" id="l_password"></div>
<br class="clear">
<div class="A3 t-right"><button class="button">Submit</button></div>
</form>
<br class="clear"><br><br>
</span>
</div>
<br class="clear">
<?php
$Page->make_Footer();
?>