-
Notifications
You must be signed in to change notification settings - Fork 3
/
membership_signup.php
299 lines (258 loc) · 11.9 KB
/
membership_signup.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
<?php
$app_name = 'Bus Booking System';
$currDir = dirname(__FILE__);
include("{$currDir}/defaultLang.php");
include("{$currDir}/language.php");
include("{$currDir}/lib.php");
include_once("{$currDir}/header.php");
$adminConfig = config('adminConfig');
if(!$cg = sqlValue("select count(1) from membership_groups where allowSignup=1")){
$noSignup = true;
echo error_message($Translation['sign up disabled']);
exit;
}
if($_POST['signUp'] != ''){
// receive data
$memberID = is_allowed_username($_POST['newUsername']);
$email = isEmail($_POST['email']);
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
$groupID = intval($_POST['groupID']);
$custom1 = makeSafe($_POST['custom1']);
$custom2 = makeSafe($_POST['custom2']);
$custom3 = makeSafe($_POST['custom3']);
$custom4 = makeSafe($_POST['custom4']);
// validate data
if(!$memberID){
echo error_message($Translation['username invalid']);
exit;
}
if(strlen($password) < 4 || trim($password) != $password){
echo error_message($Translation['password invalid']);
exit;
}
if($password != $confirmPassword){
echo error_message($Translation['password no match']);
exit;
}
if(!$email){
echo error_message($Translation['email invalid']);
exit;
}
if(!sqlValue("select count(1) from membership_groups where groupID='$groupID' and allowSignup=1")){
echo error_message($Translation['group invalid']);
exit;
}
// save member data
$needsApproval = sqlValue("select needsApproval from membership_groups where groupID='$groupID'");
sql("INSERT INTO `membership_users` set memberID='$memberID', passMD5='".md5($password)."', email='$email', signupDate='".@date('Y-m-d')."', groupID='$groupID', isBanned='0', isApproved='".($needsApproval==1 ? '0' : '1')."', custom1='$custom1', custom2='$custom2', custom3='$custom3', custom4='$custom4', comments='member signed up through the registration form.'", $eo);
// admin mail notification
/* ---- application name as provided in AppGini is used here ---- */
$message = nl2br(
"A new member has signed up for {$app_name}.\n\n" .
"Member name: {$memberID}\n" .
"Member group: " . sqlValue("select name from membership_groups where groupID='{$groupID}'") . "\n" .
"Member email: {$email}\n" .
"IP address: {$_SERVER['REMOTE_ADDR']}\n" .
"Custom fields:\n" .
($adminConfig['custom1'] ? "{$adminConfig['custom1']}: {$custom1}\n" : '') .
($adminConfig['custom2'] ? "{$adminConfig['custom2']}: {$custom2}\n" : '') .
($adminConfig['custom3'] ? "{$adminConfig['custom3']}: {$custom3}\n" : '') .
($adminConfig['custom4'] ? "{$adminConfig['custom4']}: {$custom4}\n" : '')
);
if($adminConfig['notifyAdminNewMembers'] == 2 && !$needsApproval){
sendmail(array(
'to' => $adminConfig['senderEmail'],
'subject' => "[{$app_name}] New member signup",
'message' => $message
));
}elseif($adminConfig['notifyAdminNewMembers'] >= 1 && $needsApproval){
sendmail(array(
'to' => $adminConfig['senderEmail'],
'subject' => "[{$app_name}] New member awaiting approval",
'message' => $message
));
}
// hook: member_activity
if(function_exists('member_activity')){
$args = array();
member_activity(getMemberInfo($memberID), ($needsApproval ? 'pending' : 'automatic'), $args);
}
// redirect to thanks page
$redirect = ($needsApproval ? '' : '?redir=1');
redirect("membership_thankyou.php$redirect");
exit;
}
// drop-down of groups allowing self-signup
$groupsDropDown = preg_replace('/<option.*?value="".*?><\/option>/i', '', htmlSQLSelect('groupID', "select groupID, concat(name, if(needsApproval=1, ' *', ' ')) from membership_groups where allowSignup=1 order by name", ($cg == 1 ? sqlValue("select groupID from membership_groups where allowSignup=1 order by name limit 1") : 0 )));
$groupsDropDown = str_replace('<select ', '<select class="form-control" ', $groupsDropDown);
?>
<?php if(!$noSignup){ ?>
<div class="row">
<div class="hidden-xs col-sm-4 col-md-6 col-lg-8" id="signup_splash">
<!-- customized splash content here -->
</div>
<div class="col-sm-8 col-md-6 col-lg-4">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title"><strong><?php echo $Translation['sign up here']; ?></strong></h1>
</div>
<div class="panel-body">
<form method="post" action="membership_signup.php">
<div class="form-group">
<label for="username" class="control-label"><?php echo $Translation['username']; ?></label>
<input class="form-control input-lg" type="text" required="" placeholder="<?php echo $Translation['username']; ?>" id="username" name="newUsername">
<span id="usernameAvailable" class="help-block hidden pull-left"><i class="glyphicon glyphicon-ok"></i> <?php echo str_ireplace(array("'", '"', '<memberid>'), '', $Translation['user available']); ?></span>
<span id="usernameNotAvailable" class="help-block hidden pull-left"><i class="glyphicon glyphicon-remove"></i> <?php echo str_ireplace(array("'", '"', '<memberid>'), '', $Translation['username invalid']); ?></span>
<div class="clearfix"></div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="password" class="control-label"><?php echo $Translation['password']; ?></label>
<input class="form-control" type="password" required="" placeholder="<?php echo $Translation['password']; ?>" id="password" name="password">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="confirmPassword" class="control-label"><?php echo $Translation['confirm password']; ?></label>
<input class="form-control" type="password" required="" placeholder="<?php echo $Translation['confirm password']; ?>" id="confirmPassword" name="confirmPassword">
</div>
</div>
</div>
<div class="form-group">
<label for="email" class="control-label"><?php echo $Translation['email']; ?></label>
<input class="form-control" type="text" required="" placeholder="<?php echo $Translation['email']; ?>" id="email" name="email">
</div>
<div class="form-group">
<label for="group" class="control-label"><?php echo $Translation['group']; ?></label>
<?php echo $groupsDropDown; ?>
<span class="help-block"><?php echo $Translation['groups *']; ?></span>
</div>
<?php
if(!$adminConfig['hide_custom_user_fields_during_signup']){
for($cf = 1; $cf <= 4; $cf++){
if($adminConfig['custom'.$cf] != ''){
?>
<div class="row form-group">
<div class="col-sm-3"><label class="control-label" for="custom<?php echo $cf; ?>"><?php echo $adminConfig['custom'.$cf]; ?></label></div>
<div class="col-sm-9"><input class="form-control" type="text" placeholder="<?php echo $adminConfig['custom'.$cf]; ?>" id="custom<?php echo $cf; ?>" name="custom<?php echo $cf; ?>"></div>
</div>
<?php
}
}
}
?>
<div class="row">
<div class="col-sm-offset-3 col-sm-6">
<button class="btn btn-primary btn-lg btn-block" value="signUp" id="submit" type="submit" name="signUp"><?php echo $Translation['sign up']; ?></button>
</div>
</div>
</form>
</div> <!-- /div class="panel-body" -->
</div> <!-- /div class="panel ..." -->
</div> <!-- /div class="col..." -->
</div> <!-- /div class="row" -->
<script>
$j(function() {
$j('#username').focus();
$j('#usernameAvailable, #usernameNotAvailable').click(function(){ /* */ $j('#username').focus(); });
$j('#username').on('keyup blur', checkUser);
/* password strength feedback */
$j('#password').on('keyup blur', function(){
var ps = passwordStrength($j('#password').val(), $j('#username').val());
if(ps == 'strong'){
$j('#password').parents('.form-group').removeClass('has-error has-warning').addClass('has-success');
$j('#password').attr('title', '<?php echo html_attr($Translation['Password strength: strong']); ?>');
}else if(ps == 'good'){
$j('#password').parents('.form-group').removeClass('has-success has-error').addClass('has-warning');
$j('#password').attr('title', '<?php echo html_attr($Translation['Password strength: good']); ?>');
}else{
$j('#password').parents('.form-group').removeClass('has-success has-warning').addClass('has-error');
$j('#password').attr('title', '<?php echo html_attr($Translation['Password strength: weak']); ?>');
}
});
/* inline feedback of confirm password */
$j('#confirmPassword').on('keyup blur', function(){
if($j('#confirmPassword').val() != $j('#password').val() || !$j('#confirmPassword').val().length){
$j('#confirmPassword').parents('.form-group').removeClass('has-success').addClass('has-error');
}else{
$j('#confirmPassword').parents('.form-group').removeClass('has-error').addClass('has-success');
}
});
/* inline feedback of email */
$j('#email').on('change', function(){
if(validateEmail($j('#email').val())){
$j('#email').parents('.form-group').removeClass('has-error').addClass('has-success');
}else{
$j('#email').parents('.form-group').removeClass('has-success').addClass('has-error');
}
});
/* validate form before submitting */
$j('#submit').click(function(e){ /* */ if(!jsValidateSignup()) e.preventDefault(); })
});
var uaro; // user availability request object
function checkUser(){
// abort previous request, if any
if(uaro != undefined) uaro.abort();
reset_username_status();
uaro = $j.ajax({
url: 'checkMemberID.php',
type: 'GET',
data: { 'memberID': $j('#username').val() },
success: function(resp){
var ua=resp;
if(ua.match(/\<!-- AVAILABLE --\>/)){
reset_username_status('success');
}else{
reset_username_status('error');
}
}
});
}
function reset_username_status(status){
$j('#usernameNotAvailable, #usernameAvailable')
.addClass('hidden')
.parents('.form-group')
.removeClass('has-error has-success');
if(status == undefined) return;
if(status == 'success'){
$j('#usernameAvailable')
.removeClass('hidden')
.parents('.form-group')
.addClass('has-success');
}
if(status == 'error'){
$j('#usernameNotAvailable')
.removeClass('hidden')
.parents('.form-group')
.addClass('has-error');
}
}
/* validate data before submitting */
function jsValidateSignup(){
var p1 = $j('#password').val();
var p2 = $j('#confirmPassword').val();
var email = $j('#email').val();
/* user exists? */
if(!$j('#username').parents('.form-group').hasClass('has-success')){
modal_window({ message: '<div class="alert alert-danger"><?php echo html_attr($Translation['username invalid']); ?></div>', title: "<?php echo html_attr($Translation['error:']); ?>", close: function(){ /* */ $j('#username').focus(); } });
return false;
}
/* passwords not matching? */
if(p1 != p2){
modal_window({ message: '<div class="alert alert-danger"><?php echo html_attr($Translation['password no match']); ?></div>', title: "<?php echo html_attr($Translation['error:']); ?>", close: function(){ /* */ $j('#confirmPassword').focus(); } });
return false;
}
if(!validateEmail(email)){
modal_window({ message: '<div class="alert alert-danger"><?php echo html_attr($Translation['email invalid']); ?></div>', title: "<?php echo html_attr($Translation['error:']); ?>", close: function(){ /* */ $j('#email').focus(); } });
return false;
}
return true;
}
</script>
<style>
#usernameAvailable,#usernameNotAvailable{ cursor: pointer; }
</style>
<?php } ?>
<?php include_once("{$currDir}/footer.php"); ?>