-
Notifications
You must be signed in to change notification settings - Fork 9
/
account.php
361 lines (297 loc) · 9.8 KB
/
account.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
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
// This file is part of the Huygens Remote Manager
// Copyright and license notice: see license.txt
use hrm\Nav;
use hrm\Util;
use hrm\Validator;
use hrm\user\UserManager;
require_once dirname(__FILE__) . '/inc/bootstrap.php';
global $email_sender;
/* *****************************************************************************
*
* SANITIZE INPUT
* We check the relevant contents of $_POST for validity and store them in
* a new array $clean that we will use in the rest of the code.
*
* After this step, only the $clean array and no longer the $_POST array
* should be used!
*
**************************************************************************** */
// Here we store the cleaned variables
$clean = array(
"email" => "",
"group" => "",
"pass1" => "",
"pass2" => "");
// Email
if (isset($_POST["email"])) {
if (Validator::isEmailValid($_POST["email"])) {
$clean["email"] = $_POST["email"];
}
}
// Group name
if (isset($_POST["group"])) {
if (Validator::isGroupNameValid($_POST["group"])) {
$clean["group"] = $_POST["group"];
}
}
// Passwords
if (isset($_POST["pass1"])) {
if (Validator::isPasswordValid($_POST["pass1"])) {
$clean["pass1"] = $_POST["pass1"];
}
}
if (isset($_POST["pass2"])) {
if (Validator::isPasswordValid($_POST["pass2"])) {
$clean["pass2"] = $_POST["pass2"];
}
}
if (isset($_POST["authMode"])) {
$clean["authMode"] = $_POST["authMode"];
}
/* *****************************************************************************
*
* START SESSION, CHECK LOGIN STATE, INITIALIZE WHAT NEEDED
*
**************************************************************************** */
session_start();
if (isset($_GET['home'])) {
header("Location: " . "home.php");
exit();
}
if (!isset($_SESSION['user']) || !$_SESSION['user']->isLoggedIn()) {
header("Location: " . "login.php");
exit();
}
if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], 'account')) {
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
}
if (isset($_SESSION['account_user'])) {
// Make sure the User is properly loaded
$edit_user = $_SESSION['account_user'];
} else {
$edit_user = $_SESSION['user'];
}
$message = "";
/* *****************************************************************************
*
* UPDATE USER SETTINGS
*
**************************************************************************** */
if (isset($_POST['modify'])) {
// Initialize the result to True
$result = true;
// E-mail address
if (UserManager::canModifyEmailAddress($edit_user)) {
// Check that a valid e-mail address was provided
if ($clean['email'] == "") {
$result = false;
$message = "Please fill in the email field with a valid address";
} else {
$emailToUse = $clean['email'];
}
} else {
// Use current e-mail address
$emailToUse = $edit_user->emailAddress();
}
// User group
if (UserManager::canModifyGroup($edit_user)) {
// Check that a valid group was provided
if ($clean['group'] == "") {
$result = false;
$message = "Please fill in the group field";
} else {
$groupToUse = $clean['group'];
}
} else {
// Use current group
$groupToUse = $edit_user->userGroup();
}
// Passwords
if ($clean['pass1'] == "" || $clean['pass2'] == "") {
$result = false;
$message = "Please enter a valid password in both password fields";
} else {
if ($clean['pass1'] != $clean['pass2']) {
$result = false;
$message = "Passwords do not match";
} else {
$passToUse = $clean['pass1'];
}
}
// Update the information in the database
if ($result == true) {
// Update the User information
if (UserManager::canModifyEmailAddress($edit_user)) {
$edit_user->SetEmailAddress($emailToUse);
}
if (UserManager::canModifyGroup($edit_user)) {
$edit_user->SetGroup($groupToUse);
}
try {
$success = UserManager::storeUser($edit_user, true);
} catch (Exception $e) {
$success = false;
}
if ($success == true) {
// Now we need to update the password (and update the success
// status).
$success &= UserManager::changeUserPassword($edit_user->name(), $passToUse);
}
if (!$success) {
$message = "Sorry, an error occurred and the user data could not be updated!";
} else {
// If updating some other User setting, remove the modified
// User from the session and return to the user management page.
if (isset($_SESSION['account_user'])) {
unset($_SESSION['account_user']);
$_SESSION['account_update_message'] =
"Account details successfully modified";
header("Location: " . "user_management.php");
exit();
} else {
$message = "Account details successfully modified";
$_SESSION['user'] = $edit_user;
header("Location: " . $_SESSION['referer']);
exit();
}
}
}
}
/* *****************************************************************************
*
* DISPLAY PAGE
*
**************************************************************************** */
include("header.inc.php");
?>
<!--
Tooltips
-->
<span class="toolTip" id="ttSpanCancel">Discard changes and go back to your home page.</span>
<span class="toolTip" id="ttSpanSave">Save the changes.</span>
<div id="nav">
<div id="navleft">
<ul>
<?php
echo(Nav::linkWikiPage('HuygensRemoteManagerHelpAccount'));
?>
</ul>
</div>
<div id="navright">
<ul>
<?php
echo(Nav::textUser($_SESSION['user']->name()));
echo(Nav::linkHome(Util::getThisPageName()));
?>
</ul>
</div>
<div class="clear"></div>
</div>
<div id="content">
<h3><img alt="Account" src="./images/account_title.png"
width="40"/> Your account</h3>
<form method="post" action="" id="useraccount">
<div id="account">
<?php
$somethingToChange = false;
if (UserManager::canModifyEmailAddress($edit_user)) {
$emailForForm = "";
if ($clean['email'] != "") {
$emailForForm = $clean['email'];
} else {
$emailForForm = $edit_user->emailAddress();
}
$somethingToChange = true;
?>
<label for="email">E-mail address: </label>
<input name="email"
id="email"
type="text"
value="<?php echo $emailForForm; ?>"/>
<?php
}
?>
<br/>
<?php
if (UserManager::canModifyGroup($edit_user)) {
$emailForForm = "";
if ($clean['group'] != "") {
$groupForForm = $clean['group'];
} else {
$groupForForm = $edit_user->group();
}
$somethingToChange = true;
?>
<label for="group">Research group: </label>
<input name="group"
id="group"
type="text"
value="<?php echo $groupForForm; ?>"/>
<?php
}
?>
<br/>
<?php
if (UserManager::canModifyPassword($edit_user)) {
?>
<label for="pass1">New password: </label>
<input name="pass1" id="pass1" type="password"/>
<br/>
<label for="pass2">Verify password: </label>
<input name="pass2" id="pass2" type="password"/>
<input name="modify" type="hidden" value="modify"/>
<?php
$somethingToChange = true;
}
?>
<p> </p>
<?php
$referer = $_SESSION['referer'];
?>
</div>
<?php
if ($somethingToChange == true) {
?>
<div id="controls">
<input type="button" name="cancel" value=""
class="icon cancel"
onmouseover="TagToTip('ttSpanCancel' )"
onmouseout="UnTip()"
onclick="document.location.href='<?php echo $referer ?>'"/>
<input type="button" name="save" value=""
class="icon save"
onmouseover="TagToTip('ttSpanSave' )"
onmouseout="UnTip()"
onclick="document.forms['useraccount'].submit()"/>
</div>
<?php
} else {
?>
<p>The authentication backend does not allow HRM to make any change!</p>
<div id="controls">
<input type="button" name="cancel" value=""
class="icon cancel"
onmouseover="TagToTip('ttSpanCancel' )"
onmouseout="UnTip()"
onclick="document.location.href='<?php echo $referer ?>'"/>
</div>
<?php
}
?>
</form>
</div> <!-- content -->
<div id="rightpanel">
<div id="info">
<h3>Quick help</h3>
<p>Please update the account information.</p>
</div>
<div id="message">
<?php
echo "<p>$message</p>";
?>
</div>
</div> <!-- rightpanel -->
<?php
include("footer.inc.php");
?>