forked from GibbonEdu/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publicRegistration.php
executable file
·335 lines (313 loc) · 12.9 KB
/
publicRegistration.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
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@session_start();
$proceed = false;
if (isset($_SESSION[$guid]['username']) == false) {
$enablePublicRegistration = getSettingByScope($connection2, 'User Admin', 'enablePublicRegistration');
if ($enablePublicRegistration == 'Y') {
$proceed = true;
}
}
if ($proceed == false) {
//Acess denied
echo "<div class='error'>";
echo __($guid, 'You do not have access to this action.');
echo '</div>';
} else {
//Proceed!
echo "<div class='trail'>";
echo "<div class='trailHead'><a href='".$_SESSION[$guid]['absoluteURL']."'>".__($guid, 'Home')."</a> > </div><div class='trailEnd'>".$_SESSION[$guid]['organisationNameShort'].' '.__($guid, 'Public Registration').'</div>';
echo '</div>';
$publicRegistrationMinimumAge = getSettingByScope($connection2, 'User Admin', 'publicRegistrationMinimumAge');
$returns = array();
$returns['fail5'] = sprintf(__($guid, 'Your request failed because you do not meet the minimum age for joining this site (%1$s years of age).'), $publicRegistrationMinimumAge);
$returns['fail7'] = __($guid, 'Your request failed because your password to not meet the minimum requirements for strength.');
$returns['success1'] = __($guid, 'Your registration was successfully submitted and is now pending approval. Our team will review your registration and be in touch in due course.');
$returns['success0'] = __($guid, 'Your registration was successfully submitted, and you may now log into the system using your new username and password.');
if (isset($_GET['return'])) {
returnProcess($guid, $_GET['return'], null, $returns);
}
//Get intro
$intro = getSettingByScope($connection2, 'User Admin', 'publicRegistrationIntro');
if ($intro != '') {
echo '<h3>';
echo __($guid, 'Introduction');
echo '</h3>';
echo '<p>';
echo $intro;
echo '</p>';
}
?>
<form method="post" action="<?php echo $_SESSION[$guid]['absoluteURL'].'/publicRegistrationProcess.php' ?>" enctype="multipart/form-data">
<table class='smallIntBorder fullWidth' cellspacing='0'>
<tr class='break'>
<th colspan=2>
<?php echo __($guid, 'Account Details'); ?>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'First Name') ?> *</b><br/>
</td>
<td class="right">
<input name="firstName" id="firstName" maxlength=30 value="" type="text" class="standardWidth">
<script type="text/javascript">
var firstName=new LiveValidation('firstName');
firstName.add(Validate.Presence);
</script>
</td>
</tr>
<tr>
<td style='width: 275px'>
<b><?php echo __($guid, 'Surname') ?> *</b><br/>
</td>
<td class="right">
<input name="surname" id="surname" maxlength=30 value="" type="text" class="standardWidth">
<script type="text/javascript">
var surname=new LiveValidation('surname');
surname.add(Validate.Presence);
</script>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'Email') ?> *</b><br/>
<span class="emphasis small"><?php echo __($guid, 'Must be unique.') ?></span>
</td>
<td class="right">
<input name="email" id="email" maxlength=50 value="" type="text" class="standardWidth">
<script type="text/javascript">
var email=new LiveValidation('email');
email.add(Validate.Email);
email.add(Validate.Presence);
</script>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'Gender') ?> *</b><br/>
</td>
<td class="right">
<select name="gender" id="gender" class="standardWidth">
<option value="Please select..."><?php echo __($guid, 'Please select...') ?></option>
<option value="F"><?php echo __($guid, 'Female') ?></option>
<option value="M"><?php echo __($guid, 'Male') ?></option>
<option value="Other"><?php echo __($guid, 'Other') ?></option>
<option value="Unspecified"><?php echo __($guid, 'Unspecified') ?></option>
</select>
<script type="text/javascript">
var gender=new LiveValidation('gender');
gender.add(Validate.Exclusion, { within: ['Please select...'], failureMessage: "<?php echo __($guid, 'Select something!') ?>"});
</script>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'Date of Birth') ?> *</b><br/>
<span class="emphasis small"><?php echo __($guid, 'Format:').' '.$_SESSION[$guid]['i18n']['dateFormat'] ?></span>
</td>
<td class="right">
<input name="dob" id="dob" maxlength=10 value="" type="text" class="standardWidth">
<script type="text/javascript">
var dob=new LiveValidation('dob');
dob.add( Validate.Format, {pattern: <?php if ($_SESSION[$guid]['i18n']['dateFormatRegEx'] == '') {
echo "/^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$/i";
} else {
echo $_SESSION[$guid]['i18n']['dateFormatRegEx'];
}
?>, failureMessage: "Use <?php if ($_SESSION[$guid]['i18n']['dateFormat'] == '') {
echo 'dd/mm/yyyy';
} else {
echo $_SESSION[$guid]['i18n']['dateFormat'];
}
?>." } );
dob.add(Validate.Presence);
</script>
<script type="text/javascript">
$(function() {
$( "#dob" ).datepicker();
});
</script>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'Username') ?> *</b><br/>
<span class="emphasis small"><?php echo __($guid, 'Must be unique.') ?></span>
</td>
<td class="right">
<input name="username" id="username" maxlength=20 value="" type="text" class="standardWidth"><br/><br/><br/>
<div class="LV_validation_message LV_invalid" id='username_availability_result'</div><br/>
<script type="text/javascript">
$(document).ready(function(){
$('#username').keyup(function(){
var username = $('#username').val();
$('#username_availability_result').html('<?php echo __($guid, "Checking availability...") ?>');
$.ajax({
type : 'POST',
data : { username: $('#username').val() },
url: "./publicRegistrationCheck.php",
success: function(responseText){
if(responseText == 0){
$('#username_availability_result').html('<?php echo __($guid, "Username available") ?>');
$('#username_availability_result').removeClass('LV_invalid');
$('#username_availability_result').addClass('LV_valid');
}else if(responseText > 0){
$('#username_availability_result').html('<?php echo __($guid, "Username already taken") ?>');
$('#username_availability_result').removeClass('LV_valid');
$('#username_availability_result').addClass('LV_invalid');
}else{
alert('Problem with mysql query');
}
}
});
});
});
// Validation
var username = new LiveValidation('username');
username.add(Validate.Presence);
</script>
</td>
</tr>
<tr>
<td colspan=2>
<?php
$policy = getPasswordPolicy($guid, $connection2);
if ($policy != false) {
echo "<div class='warning'>";
echo $policy;
echo '</div>';
}
?>
</td>
</tr>
<tr>
<td>
<b><?php echo __($guid, 'Password') ?> *</b><br/>
<span class="emphasis small"></span>
</td>
<td class="right">
<input type='button' class="generatePassword" value="<?php echo __($guid, 'Generate Password') ?>"/>
<input name="passwordNew" id="passwordNew" maxlength=30 value="" type="password" class="standardWidth"><br/>
<script type="text/javascript">
var passwordNew=new LiveValidation('passwordNew');
passwordNew.add(Validate.Presence);
<?php
$alpha = getSettingByScope($connection2, 'System', 'passwordPolicyAlpha');
$numeric = getSettingByScope($connection2, 'System', 'passwordPolicyNumeric');
$punctuation = getSettingByScope($connection2, 'System', 'passwordPolicyNonAlphaNumeric');
$minLength = getSettingByScope($connection2, 'System', 'passwordPolicyMinLength');
if ($alpha == 'Y') {
echo 'passwordNew.add( Validate.Format, { pattern: /.*(?=.*[a-z])(?=.*[A-Z]).*/, failureMessage: "'.__($guid, 'Does not meet password policy.').'" } );';
}
if ($numeric == 'Y') {
echo 'passwordNew.add( Validate.Format, { pattern: /.*[0-9]/, failureMessage: "'.__($guid, 'Does not meet password policy.').'" } );';
}
if ($punctuation == 'Y') {
echo 'passwordNew.add( Validate.Format, { pattern: /[^a-zA-Z0-9]/, failureMessage: "'.__($guid, 'Does not meet password policy.').'" } );';
}
if (is_numeric($minLength)) {
echo 'passwordNew.add( Validate.Length, { minimum: '.$minLength.'} );';
}
?>
$(".generatePassword").click(function(){
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789![]{}()%&*$#^<>~@|';
var text = '';
for(var i=0; i < <?php echo $minLength + 4 ?>; i++) {
for(var i=0; i < <?php echo $minLength + 4 ?>; i++) {
if (i==0) { text += chars.charAt(Math.floor(Math.random() * 26)); }
else if (i==1) { text += chars.charAt(Math.floor(Math.random() * 26)+26); }
else if (i==2) { text += chars.charAt(Math.floor(Math.random() * 10)+52); }
else if (i==3) { text += chars.charAt(Math.floor(Math.random() * 19)+62); }
else { text += chars.charAt(Math.floor(Math.random() * chars.length)); }
}
}
$('input[name="passwordNew"]').val(text);
alert('<?php echo __($guid, 'Copy this password if required:') ?>' + '\n\n' + text) ;
});
</script>
</td>
</tr>
<?php
//Privacy statement
$privacyStatement = getSettingByScope($connection2, 'User Admin', 'publicRegistrationPrivacyStatement');
if ($privacyStatement != '') {
echo "<tr class='break'>";
echo '<th colspan=2>';
echo __($guid, 'Privacy Statement');
echo '</th>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=2>';
echo '<p>';
echo $privacyStatement;
echo '</p>';
echo '</td>';
echo '</tr>';
}
//Get agreement
$agreement = getSettingByScope($connection2, 'User Admin', 'publicRegistrationAgreement');
if ($agreement != '') {
echo "<tr class='break'>";
echo '<th colspan=2>';
echo __($guid, 'Agreement');
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=2>';
echo $agreement;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<b>'.__($guid, 'Do you agree to the above?').'</b><br/>';
echo '</td>';
echo "<td class='right'>";
echo "Yes <input type='checkbox' name='agreement' id='agreement'>";
?>
<script type="text/javascript">
var agreement=new LiveValidation('agreement');
agreement.add( Validate.Acceptance );
</script>
<?php
echo '</td>';
echo '</tr>';
}
?>
<tr>
<td>
<span class="emphasis small">* <?php echo __($guid, 'denotes a required field'); ?></span>
</td>
<td class="right">
<input type="hidden" name="address" value="<?php echo $_SESSION[$guid]['address'] ?>">
<input type="submit" value="<?php echo __($guid, 'Submit'); ?>">
</td>
</tr>
</table>
</form>
<?php
//Get postscrript
$postscript = getSettingByScope($connection2, 'User Admin', 'publicRegistrationPostscript');
if ($postscript != '') {
echo '<h2>';
echo __($guid, 'Further Information');
echo '</h2>';
echo "<p style='padding-bottom: 15px'>";
echo $postscript;
echo '</p>';
}
}
?>