-
Notifications
You must be signed in to change notification settings - Fork 0
/
membership_profile.php
348 lines (299 loc) · 12.5 KB
/
membership_profile.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
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
$currDir=dirname(__FILE__);
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
$adminConfig = config('adminConfig');
/* no access for guests */
$mi = getMemberInfo();
if(!$mi['username'] || $mi['group'] == $adminConfig['anonymousGroup']){
@header('Location: index.php'); exit;
}
/* save profile */
if($_POST['action'] == 'saveProfile'){
if(!csrf_token(true)){
echo $Translation['error:'];
exit;
}
/* process inputs */
$email=isEmail($_POST['email']);
$custom1=makeSafe($_POST['custom1']);
$custom2=makeSafe($_POST['custom2']);
$custom3=makeSafe($_POST['custom3']);
$custom4=makeSafe($_POST['custom4']);
/* validate email */
if(!$email){
echo "{$Translation['error:']} {$Translation['email invalid']}";
echo "<script>$$('label[for=\"email\"]')[0].pulsate({ pulses: 10, duration: 4 }); $('email').activate();</script>";
exit;
}
/* update profile */
$updateDT = date($adminConfig['PHPDateTimeFormat']);
sql("UPDATE `membership_users` set email='$email', custom1='$custom1', custom2='$custom2', custom3='$custom3', custom4='$custom4', comments=CONCAT_WS('\\n', comments, 'member updated his profile on $updateDT from IP address {$mi[IP]}') WHERE memberID='{$mi['username']}'", $eo);
// hook: member_activity
if(function_exists('member_activity')){
$args=array();
member_activity($mi, 'profile', $args);
}
exit;
}
/* change password */
if($_POST['action'] == 'changePassword' && $mi['username'] != $adminConfig['adminUsername']){
if(!csrf_token(true)){
echo $Translation['error:'];
exit;
}
/* process inputs */
$oldPassword=$_POST['oldPassword'];
$newPassword=$_POST['newPassword'];
/* validate password */
if(md5($oldPassword) != sqlValue("SELECT `passMD5` FROM `membership_users` WHERE memberID='{$mi['username']}'")){
echo "{$Translation['error:']} {$Translation['Wrong password']}";
echo "<script>$$('label[for=\"old-password\"]')[0].pulsate({ pulses: 10, duration: 4 }); $('old-password').activate();</script>";
exit;
}
if(strlen($newPassword) < 4){
echo "{$Translation['error:']} {$Translation['password invalid']}";
echo "<script>$$('label[for=\"new-password\"]')[0].pulsate({ pulses: 10, duration: 4 }); $('new-password').activate();</script>";
exit;
}
/* update password */
$updateDT = date($adminConfig['PHPDateTimeFormat']);
sql("UPDATE `membership_users` set `passMD5`='".md5($newPassword)."', `comments`=CONCAT_WS('\\n', comments, 'member changed his password on $updateDT from IP address {$mi[IP]}') WHERE memberID='{$mi['username']}'", $eo);
// hook: member_activity
if(function_exists('member_activity')){
$args=array();
member_activity($mi, 'password', $args);
}
exit;
}
/* get profile info */
/*
$mi already contains the profile info, as documented at:
https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo
custom field names are stored in $adminConfig['custom1'] to $adminConfig['custom4']
*/
$permissions = array();
$userTables = getTableList();
if(is_array($userTables)) foreach($userTables as $tn => $tc){
$permissions[$tn] = getTablePermissions($tn);
}
/* the profile page view */
include_once("$currDir/header.php"); ?>
<div class="page-header">
<h1><?php echo sprintf($Translation['Hello user'], $mi['username']); ?></h1>
</div>
<div id="notify" class="alert alert-success" style="display: none;"></div>
<div id="loader" style="display: none;"><i class="glyphicon glyphicon-refresh"></i> <?php echo $Translation['Loading ...']; ?></div>
<?php echo csrf_token(); ?>
<div class="row">
<div class="col-md-6">
<!-- user info form -->
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-info-sign"></i>
<?php echo $Translation['Your info']; ?>
</h3>
</div>
<div class="panel-body">
<fieldset id="profile">
<div class="form-group">
<label for="email"><?php echo $Translation['email']; ?></label>
<input type="email" id="email" name="email" value="<?php echo $mi['email']; ?>" class="form-control">
</div>
<?php for($i=1; $i<5; $i++){ ?>
<div class="form-group">
<label for="custom<?php echo $i; ?>"><?php echo $adminConfig['custom'.$i]; ?></label>
<input type="text" id="custom<?php echo $i; ?>" name="custom<?php echo $i; ?>" value="<?php echo $mi['custom'][$i-1]; ?>" class="form-control">
</div>
<?php } ?>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<button id="update-profile" class="btn btn-success btn-block" type="button"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['Update profile']; ?></button>
</div>
</div>
</fieldset>
</div>
</div>
<!-- access permissions -->
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-lock"></i>
<?php echo $Translation['Your access permissions']; ?>
</h3>
</div>
<div class="panel-body">
<p><strong><?php echo $Translation['Legend']; ?></strong></p>
<div class="row">
<div class="col-xs-2 col-md-1 text-right"><img src="admin/images/stop_icon.gif"></div>
<div class="col-xs-10 col-md-5"><?php echo $Translation['Not allowed']; ?></div>
<div class="col-xs-2 col-md-1 text-right"><img src="admin/images/member_icon.gif"></div>
<div class="col-xs-10 col-md-5"><?php echo $Translation['Only your own records']; ?></div>
</div>
<div class="row">
<div class="col-xs-2 col-md-1 text-right"><img src="admin/images/members_icon.gif"></div>
<div class="col-xs-10 col-md-5"><?php echo $Translation['All records owned by your group']; ?></div>
<div class="col-xs-2 col-md-1 text-right"><img src="admin/images/approve_icon.gif"></div>
<div class="col-xs-10 col-md-5"><?php echo $Translation['All records']; ?></div>
</div>
<p class="vspacer-lg"></p>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered" id="permissions">
<thead>
<tr>
<th><?php echo $Translation['Table']; ?></th>
<th class="text-center"><?php echo $Translation['View']; ?></th>
<th class="text-center"><?php echo $Translation['Add New']; ?></th>
<th class="text-center"><?php echo $Translation['Edit']; ?></th>
<th class="text-center"><?php echo $Translation['Delete']; ?></th>
</tr>
</thead>
<tbody>
<?php foreach($permissions as $tn => $perm){ ?>
<tr>
<td><img src="<?php echo $userTables[$tn][2]; ?>"> <a href="<?php echo $tn; ?>_view.php"><?php echo $userTables[$tn][0]; ?></a></td>
<td class="text-center"><img src="admin/images/<?php echo permIcon($perm[2]); ?>" /></td>
<td class="text-center"><img src="admin/images/<?php echo ($perm[1] ? 'approve' : 'stop'); ?>_icon.gif" /></td>
<td class="text-center"><img src="admin/images/<?php echo permIcon($perm[3]); ?>" /></td>
<td class="text-center"><img src="admin/images/<?php echo permIcon($perm[4]); ?>" /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<!-- group and IP address -->
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group">
<label><?php echo $Translation['Your IP address']; ?></label>
<div class="form-control-static"><?php echo $mi['IP']; ?></div>
</div>
</div>
</div>
<!-- group and IP address -->
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group">
<label><?php echo $Translation['group']; ?></label>
<div class="form-control-static"><?php echo $mi['group']; ?></div>
</div>
</div>
</div>
<?php if($mi['username'] != $adminConfig['adminUsername']){ ?>
<!-- change password -->
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">
<i class="glyphicon glyphicon-asterisk"></i><i class="glyphicon glyphicon-asterisk"></i>
<?php echo $Translation['Change your password']; ?>
</h3>
</div>
<div class="panel-body">
<fieldset id="change-password">
<div id="password-change-form">
<div class="form-group">
<label for="old-password"><?php echo $Translation['Old password']; ?></label>
<input type="password" id="old-password" autocomplete="off" class="form-control">
</div>
<div class="form-group">
<label for="new-password"><?php echo $Translation['new password']; ?></label>
<input type="password" id="new-password" autocomplete="off" class="form-control">
<p id="password-strength" class="help-block"></p>
</div>
<div class="form-group">
<label for="confirm-password"><?php echo $Translation['confirm password']; ?></label>
<input type="password" id="confirm-password" autocomplete="off" class="form-control">
<p id="confirm-status" class="help-block"></p>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<button id="update-password" class="btn btn-success btn-block" type="button"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['Update password']; ?></button>
</div>
</div>
</div>
</fieldset>
</div>
</div>
<?php } ?>
</div>
</div>
<script>
$j(function() {
<?php
/* Is there a notification to display? */
$notify = '';
if(isset($_GET['notify'])) $notify = addslashes(strip_tags($_GET['notify']));
?>
<?php if($notify){ ?> notify('<?php echo $notify; ?>'); <?php } ?>
$('update-profile').observe('click', function(){
post2(
'<?php echo basename(__FILE__); ?>',
{ action: 'saveProfile', email: $F('email'), custom1: $F('custom1'), custom2: $F('custom2'), custom3: $F('custom3'), custom4: $F('custom4'), csrf_token: $F('csrf_token') },
'notify', 'profile', 'loader',
'<?php echo basename(__FILE__); ?>?notify=<?php echo urlencode($Translation['Your profile was updated successfully']); ?>'
);
});
<?php if($mi['username'] != $adminConfig['adminUsername']){ ?>
$('update-password').observe('click', function(){
/* make sure passwords match */
if($F('new-password') != $F('confirm-password')){
$('notify').addClassName('Error');
notify('<?php echo "{$Translation['error:']} ".addslashes($Translation['password no match']); ?>');
$$('label[for="confirm-password"]')[0].pulsate({ pulses: 10, duration: 4 });
$('confirm-password').activate();
return false;
}
post2(
'<?php echo basename(__FILE__); ?>',
{ action: 'changePassword', oldPassword: $F('old-password'), newPassword: $F('new-password'), csrf_token: $F('csrf_token') },
'notify', 'password-change-form', 'loader',
'<?php echo basename(__FILE__); ?>?notify=<?php echo urlencode($Translation['Your password was changed successfully']); ?>'
);
});
/* password strength feedback */
$('new-password').observe('keyup', function(){
ps = passwordStrength($F('new-password'), '<?php echo addslashes($mi['username']); ?>');
if(ps == 'strong')
$('password-strength').update('<?php echo $Translation['Password strength: strong']; ?>').setStyle({color: 'Green'});
else if(ps == 'good')
$('password-strength').update('<?php echo $Translation['Password strength: good']; ?>').setStyle({color: 'Gold'});
else
$('password-strength').update('<?php echo $Translation['Password strength: weak']; ?>').setStyle({color: 'Red'});
});
/* inline feedback of confirm password */
$('confirm-password').observe('keyup', function(){
if($F('confirm-password') != $F('new-password') || !$F('confirm-password').length){
$('confirm-status').update('<img align="top" src="Exit.gif"/>');
}else{
$('confirm-status').update('<img align="top" src="update.gif"/>');
}
});
<?php } ?>
});
function notify(msg){
$j('#notify').html(msg).fadeIn();
window.setTimeout(function(){ $j('#notify').fadeOut(); }, 15000);
}
</script>
<?php
/* return icon file name based on given permission value */
function permIcon($perm){
switch($perm){
case 1:
return 'member_icon.gif';
case 2:
return 'members_icon.gif';
case 3:
return 'approve_icon.gif';
default:
return 'stop_icon.gif';
}
}
?>
<?php include_once("$currDir/footer.php"); ?>