-
Notifications
You must be signed in to change notification settings - Fork 9
/
registration.php
303 lines (236 loc) · 7.55 KB
/
registration.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
<?php
// This file is part of the Huygens Remote Manager
// Copyright and license notice: see license.txt
use hrm\Mail;
use hrm\Nav;
use hrm\user\UserConstants;
use hrm\user\UserManager;
use hrm\Validator;
require_once dirname(__FILE__) . '/inc/bootstrap.php';
global $hrm_url;
global $email_sender;
global $email_admin;
$processed = False;
$message = "";
/*
*
* 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(
"username" => "",
"email" => '',
"group" => "",
"pass1" => "",
"pass2" => "",
"note" => "");
// Username
if (isset($_POST["username"])) {
if (Validator::isUserNameValid($_POST["username"])) {
$clean["username"] = $_POST["username"];
}
}
// 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"];
}
}
// Note
if (isset($_POST["note"])) {
if (Validator::isNoteValid($_POST["note"])) {
$clean["note"] = $_POST["note"];
}
}
/*
*
* END OF SANITIZE INPUT
*
*/
if (isset($_POST["OK"])) {
// Check whether all fields have been correctly filled and whether the user
// already exists
if ($clean["username"] == "") {
$message = "Please provide a valid user name.";
} else if ($clean["email"] == "") {
$message = "Please provide a valid e-mail address.";
} else if ($clean["group"] == "") {
$message = "Please provide a group.";
} else if ($clean["pass1"] == "" || $clean["pass2"] == "") {
$message = "Please provide your password (twice).";
} else if ($clean["pass1"] == $clean["pass2"]) {
// Make sure that there is no user with same name
if (UserManager::existsUserWithName($clean['username'])) {
$name = $clean['username'];
$message = "Sorry, a user with name $name exists already!";
} else {
// Create the new user
$institution_id = 1;
$uniqueId = UserManager::generateUniqueId();
$result = UserManager::createUser($clean["username"],
$clean["pass1"], $clean["email"], $clean["group"],
$institution_id, "integrated",
UserConstants::ROLE_USER,
UserConstants::STATUS_NEW_ACCOUNT,
$uniqueId);
// TODO refactor
if ($result) {
$text = "New user registration:\n\n";
$text .= "\t Username: " . $clean["username"] . "\n";
$text .= "\t E-mail address: " . $clean["email"] . "\n";
$text .= "\t Group: " . $clean["group"] . "\n";
$text .= "\tRequest message: " . $clean["note"] . "\n\n";
$text .= "Accept or reject this user here (login required)\n";
$text .= $hrm_url . "/user_management.php?seed=" . $uniqueId;
$mail = new Mail($email_sender);
$mail->setReceiver($email_admin);
$mail->setSubject("New HRM user registration");
$mail->setMessage($text);
if ($mail->send()) {
$notice = "Application successfully sent!\n" .
"Your application will be processed by the " .
"administrator and you will receive a confirmation " .
"by e-mail.";
} else {
$notice = "Your application was successfully stored, " .
"but there was an error e-mailing the administrator! " .
"Please contact him directly.";
}
$processed = True;
} else {
$message = "Could not create user! Please contact your administrator.";
}
}
} else {
$message = "Passwords do not match!";
}
}
include("header.inc.php");
?>
<div id="nav">
<div id="navleft">
<ul>
<?php
echo(Nav::linkWikiPage('HuygensRemoteManagerHelpRegistrationPage'));
?>
</ul>
</div>
<div id="navright">
<ul>
<?php
echo(Nav::exitToLogin());
?>
</ul>
</div>
<div class="clear"></div>
</div>
<div id="content">
<h3>Registration</h3>
<?php
if (!$processed) {
?>
<form method="post" action="">
<div id="adduser">
<div>
<label for="username">* Username: </label>
<input type="text"
name="username"
id="username"
maxlength="30"
value="<?php echo $clean["username"] ?>"/>
</div>
<div>
<label for="email">* E-mail address: </label>
<input type="text"
name="email"
id="email"
maxlength="80"
value="<?php echo $clean["email"] ?>"/>
</div>
<div>
<label for="group">* Research group: </label>
<input type="text"
name="group"
id="group"
maxlength="30"
value="<?php echo $clean["group"] ?>"/>
</div>
<div>
<label for="pass1">* Password: </label>
<input type="password"
name="pass1"
id="pass1"/>
</div>
<div>
<label for="pass2">* (verify) Password: </label>
<input type="password"
name="pass2"
id="pass2"/>
</div>
<div>
<textarea name="note"
placeholder="Request message (optional)..."
id="note"
rows="3"
class="selection"
cols="30"><?php if ($clean["note"] != "") { echo($clean["note"]); } ?>
</textarea>
</div>
<div>
<input name="OK"
type="submit"
value="register"/>
</div>
</div>
</form>
<?php
} else {
?>
<div id="notice"><?php echo "<p>$notice</p>"; ?></div>
<?php
}
?>
</div> <!-- content -->
<div id="rightpanel">
<?php
if (!$processed) {
?>
<div id="info">
<h3>Quick help</h3>
<p>* Required fields.</p>
</div>
<?php
}
?>
<div id="message">
<?php
echo "<p>$message</p>";
?>
</div>
</div> <!-- rightpanel -->
<?php
include("footer.inc.php");
?>