]>
Commit | Line | Data |
---|---|---|
78069032 | 1 | <?php |
cd1dee97 BM |
2 | /* Log the user out if it was logged in. |
3 | * This is mostly for devs running the install screen and | |
4 | * fater succeeding the first screen suddenly being logged in | |
5 | * with old credentials/uid weirdness. | |
6 | * Code from example #1 at https://www.php.net/manual/en/function.session-destroy.php | |
7 | */ | |
8 | session_start(); | |
9 | $_SESSION = Array(); | |
10 | if (ini_get("session.use_cookies")) { | |
11 | $params = session_get_cookie_params(); | |
12 | setcookie(session_name(), '', time() - 42000, | |
13 | $params["path"], $params["domain"], | |
14 | $params["secure"], $params["httponly"] | |
15 | ); | |
16 | } | |
17 | session_destroy(); | |
78069032 | 18 | |
c06c1713 | 19 | require_once "../inc/common.php"; |
78069032 | 20 | |
9680dd58 | 21 | /* Get the base url */ |
973acaa9 | 22 | $uri = $_SERVER['REQUEST_URI']; |
9680dd58 | 23 | $tok = split($uri, "/"); |
2dbe2544 | 24 | $base_url = ""; |
9680dd58 VP |
25 | for ($i=0; isset($tok[$i]); $i++) |
26 | { | |
2dbe2544 | 27 | if ($tok[$i] == "settings" && strstr($tok[$i + 1], "install.php")) |
9680dd58 | 28 | { |
9680dd58 VP |
29 | if ($i) |
30 | { | |
31 | for($j=0; $j < $i; $j++) | |
32 | { | |
33 | strcat($base_url,$tok[$j]); | |
34 | strcat($base_url,"/"); | |
35 | } | |
36 | } | |
9680dd58 VP |
37 | } |
38 | } | |
2dbe2544 VP |
39 | if (!strlen($base_url)) |
40 | $base_url = "/"; | |
41 | define('BASE_URL', $base_url); | |
42 | ||
78069032 VP |
43 | $writable = (is_writable("../config/")) ? true: false; |
44 | ?> | |
45 | <!DOCTYPE html> | |
46 | <head> | |
47 | <div class="media"> | |
48 | <div class="media-body"> | |
49 | ||
50 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
51 | <meta name="HandheldFriendly" content="true"> | |
52 | ||
78069032 VP |
53 | |
54 | ||
55 | <!-- Latest compiled and minified CSS --> | |
56 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"> | |
57 | ||
58 | <!-- Font Awesome JS --> | |
59 | <script defer src="https://use.fontawesome.com/releases/v6.2.1/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script> | |
60 | <script defer src="https://use.fontawesome.com/releases/v6.2.1/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script> | |
61 | ||
62 | <!-- Font Awesome icons --> | |
63 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"> | |
2dbe2544 | 64 | <script src="../js/unrealircd-admin.js"></script> |
78069032 VP |
65 | <title>UnrealIRCd Panel</title> |
66 | <link rel="icon" type="image/x-icon" href="<?php echo get_config("base_url"); ?>img/favicon.ico"> | |
67 | ||
68 | <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
69 | <!-- Popper.JS --> | |
70 | <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script> | |
71 | <!-- Bootstrap JS --> | |
72 | <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> | |
73 | </div></div> | |
74 | </head> | |
75 | ||
76 | <body role="document"> | |
77 | ||
2dbe2544 | 78 | <div class="container mt-4"><div class="row justify-content-center"><img src="../img/unreal.jpg" width="35px" height="35px" style="margin-right: 15px"><h3>UnrealIRCd Admin Panel Configuration and Setup</h3></div></div> |
9680dd58 | 79 | <?php |
78069032 VP |
80 | |
81 | if (file_exists("../config/config.php")) | |
82 | { | |
2dbe2544 | 83 | ?><br><div class="container"><?php Message::Fail("You're already configured!"); ?> |
78069032 VP |
84 | <br> |
85 | <a class="text-center btn btn-primary" href="<?php echo BASE_URL; ?>">Take me home!</a> | |
86 | </div> | |
87 | <?php | |
88 | return; | |
89 | } | |
2dbe2544 | 90 | elseif (isset($_POST) && !empty($_POST)) |
9680dd58 | 91 | { |
2dbe2544 VP |
92 | ?><br><div class="container"><?php |
93 | $opts = (object)$_POST; | |
9680dd58 | 94 | /* pre-load the appropriate auth plugin */ |
9680dd58 | 95 | $auth_method = (isset($opts->auth_method)) ? $opts->auth_method : NULL; |
2dbe2544 VP |
96 | $auth_method_name = NULL; |
97 | switch($auth_method) | |
98 | { | |
ce25dde2 BM |
99 | case "sql_db": |
100 | $auth_method_name = "SQLDB"; | |
2dbe2544 | 101 | break; |
ce25dde2 BM |
102 | case "file_db": |
103 | $auth_method_name = "FileDB"; | |
2dbe2544 VP |
104 | break; |
105 | } | |
9680dd58 | 106 | if ($auth_method) |
2dbe2544 | 107 | $am = new Plugin($auth_method); |
9680dd58 | 108 | else |
2dbe2544 VP |
109 | { |
110 | Message::Fail("Invalid parameters"); | |
111 | return; | |
112 | } | |
113 | if ($am->error) | |
114 | { | |
115 | Message::Fail("Couldn't load plugin \"$auth_method\": $am->error"); | |
116 | return; | |
117 | } | |
118 | ||
54b9603c BM |
119 | $config["base_url"] = BASE_URL; |
120 | $config["plugins"] = Array("$auth_method"); | |
ce25dde2 | 121 | if ($auth_method == "sql_db") |
2dbe2544 | 122 | { |
54b9603c BM |
123 | $config["mysql"] = [ |
124 | "host" => $opts->sql_host, | |
125 | "database" => $opts->sql_db, | |
126 | "username" => $opts->sql_user, | |
127 | "password" => $opts->sql_password, | |
ca3c76f7 | 128 | "table_prefix" => $opts->sql_table_prefix, |
b41fa16f | 129 | ]; |
54b9603c | 130 | } |
b41fa16f | 131 | |
474d4966 BM |
132 | generate_secrets(); |
133 | ||
54b9603c BM |
134 | /* First, write only the config file */ |
135 | write_config_file(); | |
136 | ||
ce25dde2 | 137 | if ($auth_method == "sql_db") |
1bbc51fb | 138 | { |
ce25dde2 BM |
139 | sql_db::delete_tables(); |
140 | if (!sql_db::create_tables()) | |
54b9603c | 141 | Message::Fail("Could not create SQL tables"); |
ce25dde2 | 142 | } else if ($auth_method == "file_db") |
57eb6560 | 143 | { |
ce25dde2 | 144 | file_db::delete_db(); |
1bbc51fb | 145 | } |
54b9603c BM |
146 | |
147 | $user = [ | |
148 | "user_name" => $opts->account_user, | |
149 | "user_pass" => $opts->account_password, | |
150 | "fname" => $opts->account_fname, | |
151 | "lname" => $opts->account_lname, | |
152 | "user_bio" => $opts->account_bio, | |
153 | "email" => $opts->account_email | |
154 | ]; | |
155 | ||
156 | create_new_user($user); | |
157 | $lkup = new PanelUser($opts->account_user); | |
158 | if (!$lkup->id) | |
159 | { | |
160 | Message::Fail("Could not create user"); | |
2dbe2544 VP |
161 | return; |
162 | } | |
6f0e7ce4 | 163 | $lkup->add_meta('role', 'Super-Admin'); |
54b9603c BM |
164 | |
165 | /* Now, write all the config (config.php + settings in DB) */ | |
166 | write_config(); | |
167 | ?> | |
168 | <br> | |
169 | The configuration file has been written. Now, log in to the panel to proceed with the rest of the installation.<br><br> | |
170 | <a class="text-center btn btn-primary" href="<?php echo BASE_URL; ?>">Let's go!</a></div> | |
171 | <?php | |
172 | return; | |
9680dd58 | 173 | } |
78069032 VP |
174 | |
175 | ?> | |
9680dd58 VP |
176 | <style> |
177 | table tr td { | |
178 | font-style: italic; | |
179 | } | |
180 | </style> | |
54b9603c | 181 | <?php if (!$writable) { ?> |
78069032 VP |
182 | <div id="page1" class="container"> |
183 | <br> | |
54b9603c BM |
184 | The admin panel needs to be able to write the config file.<br> |
185 | Please run: <code>sudo chown <?php echo get_current_user(); ?> <?php echo UPATH; ?> -R</code><br> | |
186 | And after that, refresh this webpage.<br><br> | |
187 | If you have any questions about this, read <a href="https://www.unrealircd.org/docs/UnrealIRCd_webpanel#Permissions" target="_blank">the installation manual on permissions</a>. | |
78069032 | 188 | </div> |
54b9603c BM |
189 | <?php |
190 | die; | |
191 | } ?> | |
78069032 VP |
192 | |
193 | <!-- Form start --> | |
2dbe2544 | 194 | <form method="post"> |
78069032 | 195 | <div id="page3" class="container"> |
ce25dde2 | 196 | <h5>Database Backend</h5> |
78069032 | 197 | <br> |
ce25dde2 | 198 | Which database backend would you like to use? |
78069032 VP |
199 | <br><br> |
200 | Please choose from the available options: | |
201 | <div class="form-group"> | |
202 | <div class="form-check"> | |
ce25dde2 BM |
203 | <input class="form-check-input" type="radio" name="auth_method" id="file_db_radio" value="file_db"> |
204 | <label class="form-check-label" for="file_db_radio"> | |
205 | File-based database (Uses local files as a database, no additional setup needed) | |
78069032 VP |
206 | </label> |
207 | </div> | |
208 | <div class="form-check"> | |
ce25dde2 BM |
209 | <input class="form-check-input" type="radio" name="auth_method" id="sql_db_radio" value="sql_db"> |
210 | <label class="form-check-label" for="sql_db_radio"> | |
211 | SQL Database (Requires an SQL database) | |
78069032 VP |
212 | </label> |
213 | </div> | |
214 | </div> | |
215 | <br> | |
216 | <div id="sql_form" style="display:none"> | |
217 | Please enter your SQL information. <div id="sql_instructions" class="ml-4 btn btn-sm btn-info">View instructions</div> | |
218 | <div class="form-group"> | |
036c24c5 BM |
219 | <label for="sql_host">Hostname or IP</label> |
220 | <input name="sql_host" type="text" class="revalidation-needed-sql form-control" id="sql_host" aria-describedby="hostname_help" value="127.0.0.1"> | |
78069032 VP |
221 | <small id="hostname_help" class="form-text text-muted">The hostname or IP address of your SQL server. You should use <code>127.0.0.1</code> for the same machine.</small> |
222 | </div> | |
223 | <div class="form-group"> | |
224 | <label for="sql_db">Database name</label> | |
f0106ef0 | 225 | <input name="sql_db" type="text" class="revalidation-needed-sql form-control" id="sql_db" aria-describedby="port_help"> |
78069032 VP |
226 | <small id="port_help" class="form-text text-muted">The name of the SQL database to write to and read from.</small> |
227 | </div> | |
228 | <div class="form-group"> | |
229 | <label for="sql_username">Username</label> | |
17cca93a | 230 | <input name="sql_user" type="text" class="revalidation-needed-sql form-control" id="sql_user" aria-describedby="username_help" autocomplete="new-password"> |
78069032 VP |
231 | <small id="username_help" class="form-text text-muted">The name of SQL user</small> |
232 | </div> | |
233 | <div class="form-group"> | |
234 | <label for="sql_password">Password</label> | |
17cca93a | 235 | <input name="sql_password" type="password" class="revalidation-needed-sql form-control" id="sql_password" autocomplete="new-password"> |
78069032 | 236 | </div> |
ca3c76f7 BM |
237 | <div class="form-group"> |
238 | <label for="sql_table_prefix">Table prefix</label> | |
239 | <input name="sql_table_prefix" type="text" class="revalidation-needed-sql form-control" id="sql_table_prefix" aria-describedby="sql_table_prefix_help" value="unreal_"> | |
240 | <small id="sql_table_prefix_help" class="form-text text-muted">The prefix for table names (leave blank for none)</small> | |
241 | </div> | |
78069032 VP |
242 | </div> |
243 | <div class="text-center"> | |
78069032 VP |
244 | <div id="page3_next" class="btn btn-primary ml-3">Next</div> |
245 | <div id="page3_test_connection" class="btn btn-primary ml-3" style="display: none">Test connection</div> | |
246 | </div> | |
247 | </div> | |
f0106ef0 | 248 | <div id="page4" class="container" > |
78069032 VP |
249 | <h5>Create your account</h5> |
250 | <br> | |
54b9603c | 251 | You need an account, let's make one.<br><br> |
78069032 | 252 | <div class="form-group"> |
f0106ef0 | 253 | <label for="account_user" id="userlabel">Pick a username</label> |
78069032 | 254 | <input name="account_user" type="text" class="form-control" id="account_user" aria-describedby="username_help"> |
f0106ef0 | 255 | <small id="username_help" class="form-text text-muted">Pick a username! Please make sure it's at least 3 characters long, contains no spaces, and is made of only letters and numbers.</small> |
78069032 VP |
256 | </div> |
257 | <div class="form-group"> | |
f0106ef0 | 258 | <label for="account_password" id="passlabel">Password</label> |
78069032 VP |
259 | <input name="account_password" type="password" class="form-control" id="account_password" aria-describedby="password_help"> |
260 | <small id="password_help" class="form-text text-muted">Please choose a password that at least 8 characters long, contains at least one uppercase letter, one lowercase letter, one number and one symbol.</small> | |
261 | </div> | |
262 | <div class="form-group"> | |
f0106ef0 | 263 | <label for="account_password_conf" id="passconflabel">Confirm password</label> |
78069032 | 264 | <input name="account_password_conf" type="password" class="form-control" id="account_password_conf"> |
78069032 VP |
265 | </div> |
266 | <div class="form-group"> | |
f0106ef0 | 267 | <label for="account_email" id="emaillabel">Email address</label> |
78069032 | 268 | <input name="account_email" type="text" class="form-control" id="account_email" aria-describedby="email_help"> |
78069032 VP |
269 | </div> |
270 | <div class="form-group"> | |
f0106ef0 | 271 | <label for="account_fname" id="fnamelabel">First name</label> |
9680dd58 | 272 | <input name="account_fname" type="text" class="form-control" id="account_fname"> |
78069032 VP |
273 | </div> |
274 | <div class="form-group"> | |
f0106ef0 | 275 | <label for="account_lname" id="lnamelabel">Last name</label> |
78069032 VP |
276 | <input name="account_lname" type="text" class="form-control" id="account_lname"> |
277 | </div> | |
278 | <div class="form-group"> | |
f0106ef0 | 279 | <label for="account_bio" id="biolabel">Bio</label> |
78069032 VP |
280 | <textarea name="account_bio" type="text" class="form-control" id="account_bio"></textarea> |
281 | </div> | |
282 | <div class="text-center"> | |
283 | <div id="page4_back" class="btn btn-secondary mr-3">Back</div> | |
9680dd58 VP |
284 | <button id="page4_next" type="submit" class="btn btn-primary ml-3">Submit</div> |
285 | </div> | |
286 | </div> | |
78069032 | 287 | </form> |
6f2b5b4b BM |
288 | |
289 | <!-- Database overwrite prompt --> | |
eddacbaa BM |
290 | <div class="modal fade" id="db_overwrite_modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> |
291 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
292 | <div class="modal-content"> | |
293 | <div class="modal-header"> | |
294 | <h5 class="modal-title" id="myModalLabel">Database already contains data</h5> | |
295 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
296 | <span aria-hidden="true">×</span> | |
297 | </button> | |
298 | </div> | |
299 | <div class="modal-body"> | |
224b44c8 | 300 | The database already exists and contains data. |
eddacbaa BM |
301 | If you continue then this existing data will be deleted. |
302 | </div> | |
303 | <div class="modal-footer"> | |
304 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
305 | <button id="ProceedButton" type="button" class="btn btn-danger" onclick="nextstep();">Continue</button> | |
306 | </form> | |
307 | </div> | |
308 | </div> | |
309 | </div> | |
310 | </div> | |
311 | ||
6f2b5b4b BM |
312 | <!-- Database error dialog --> |
313 | <div class="modal fade" id="db_error_modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> | |
314 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
315 | <div class="modal-content"> | |
316 | <div class="modal-header"> | |
317 | <h5 class="modal-title" id="myModalLabel">Database server error</h5> | |
318 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
319 | <span aria-hidden="true">×</span> | |
320 | </button> | |
321 | </div> | |
322 | <div class="modal-body" id="db_error_text"> | |
323 | Unable to connect to the database. | |
324 | </div> | |
325 | <div class="modal-footer"> | |
326 | <button id="CloseButton" type="button" class="btn btn-primary" data-dismiss="modal">Ok</button> | |
327 | </form> | |
328 | </div> | |
329 | </div> | |
330 | </div> | |
331 | </div> | |
332 | ||
78069032 VP |
333 | <script> |
334 | let BASE_URL = '<?php echo BASE_URL; ?>'; | |
335 | let chmod_help = document.getElementById('chmod_help'); | |
336 | ||
337 | if (chmod_help) | |
338 | chmod_help.addEventListener('click', e => { | |
339 | window.open("https://www.unrealircd.org/docs/UnrealIRCd_webpanel#Permissions"); | |
340 | }); | |
341 | ||
78069032 | 342 | let page3 = document.getElementById('page3'); |
9680dd58 | 343 | let page4 = document.getElementById('page4'); |
78069032 | 344 | |
ce25dde2 BM |
345 | let file_db_radio = document.getElementById('file_db_radio'); |
346 | let sql_db_radio = document.getElementById('sql_db_radio'); | |
78069032 | 347 | let sql_form = document.getElementById('sql_form'); |
036c24c5 | 348 | let sql_host = document.getElementById('sql_host'); |
78069032 VP |
349 | let sql_db = document.getElementById('sql_db'); |
350 | let sql_user = document.getElementById('sql_user'); | |
351 | let sql_pass = document.getElementById('sql_password'); | |
352 | let sql_test_conn = document.getElementById('page3_test_connection'); | |
78069032 VP |
353 | let page3_next = document.getElementById('page3_next'); |
354 | ||
78069032 VP |
355 | let page4_back = document.getElementById('page4_back'); |
356 | let page4_next = document.getElementById('page4_next'); | |
78069032 | 357 | |
54b9603c | 358 | page4.style.display = 'none'; |
9680dd58 | 359 | |
f0106ef0 VP |
360 | revalidate_sql = document.querySelectorAll('.revalidation-needed-sql'); |
361 | for (let i = 0; i < revalidate_sql.length; i++) | |
362 | { | |
363 | revalidate_sql[i].addEventListener('input', e => { | |
364 | page3_next.style.display = 'none'; | |
365 | sql_test_conn.innerHTML = 'Test connection'; | |
366 | sql_test_conn.style.display = ''; | |
367 | sql_test_conn.classList.remove('disabled'); | |
368 | }); | |
369 | } | |
9680dd58 | 370 | |
78069032 | 371 | page3_next.addEventListener('click', e => { |
224b44c8 BM |
372 | <?php if (file_exists(UPATH.'/data/database.php')) { ?> |
373 | $('#db_overwrite_modal').modal(); | |
374 | e.preventDefault(); | |
375 | return false; | |
376 | <?php } ?> | |
78069032 VP |
377 | page3.style.display = 'none'; |
378 | page4.style.display = ''; | |
379 | }); | |
380 | ||
ce25dde2 BM |
381 | file_db_radio.addEventListener('click', e => { |
382 | if (file_db_radio.checked){ | |
78069032 VP |
383 | sql_form.style.display = 'none'; |
384 | sql_test_conn.style.display = 'none'; | |
385 | page3_next.style.display = ''; | |
386 | } | |
387 | }); | |
9680dd58 | 388 | |
ce25dde2 BM |
389 | sql_db_radio.addEventListener('click', e => { |
390 | if (!file_db_radio.checked){ | |
78069032 VP |
391 | sql_form.style.display = ''; |
392 | sql_test_conn.style.display = ''; | |
393 | page3_next.style.display = 'none'; | |
394 | } | |
395 | }); | |
396 | ||
397 | sql_instructions.addEventListener('click', e => { | |
398 | window.open("https://www.unrealircd.org/docs/UnrealIRCd_webpanel#SQL_Authentication"); | |
399 | }); | |
400 | ||
401 | sql_test_conn.addEventListener('click', e => { | |
402 | sql_test_conn.classList.add('disabled'); | |
403 | sql_test_conn.innerHTML = "Checking..."; | |
055ded3a BM |
404 | fetch(BASE_URL + 'api/installation.php', { |
405 | method:'POST', | |
406 | headers: {'Content-Type':'application/x-www-form-urlencoded'}, | |
407 | body: 'method=sql&'+ | |
408 | 'host='+encodeURIComponent(sql_host.value)+ | |
409 | '&database='+encodeURIComponent(sql_db.value)+ | |
410 | '&user='+encodeURIComponent(sql_user.value)+ | |
eddacbaa BM |
411 | '&password='+encodeURIComponent(sql_pass.value)+ |
412 | '&table_prefix='+encodeURIComponent(sql_table_prefix.value) | |
055ded3a | 413 | }) |
78069032 VP |
414 | .then(response => response.json()) |
415 | .then(data => { | |
416 | if (data.success) | |
417 | { | |
eddacbaa BM |
418 | nextstep(); |
419 | } else | |
420 | if (data.warn) | |
421 | { | |
422 | $('#db_overwrite_modal').modal(); | |
78069032 VP |
423 | } |
424 | else | |
425 | { | |
426 | sql_test_conn.innerHTML = "Failed!"; | |
6f2b5b4b BM |
427 | $('#db_error_text').html(data.error ? data.error : 'An error occured while connecting to the DB server'); |
428 | $('#db_error_modal').modal(); | |
78069032 VP |
429 | setTimeout(function() { |
430 | sql_test_conn.innerHTML = "Test connection"; | |
431 | sql_test_conn.classList.remove('disabled'); | |
432 | }, 2000); | |
433 | } | |
434 | }) | |
435 | .catch(error => { | |
436 | sql_test_conn.innerHTML = "Failed!"; | |
437 | setTimeout(function() { | |
438 | sql_test_conn.innerHTML = "Test connection"; | |
439 | sql_test_conn.classList.remove('disabled'); | |
440 | }, 2000); | |
441 | }); | |
f0106ef0 | 442 | }); |
78069032 | 443 | |
f0106ef0 VP |
444 | user_name_label = document.getElementById('userlabel'); |
445 | user_name = document.getElementById('account_user'); | |
446 | user_pass_label = document.getElementById('passlabel'); | |
447 | user_pass = document.getElementById('account_password'); | |
448 | user_pass2_label = document.getElementById('passconflabel'); | |
449 | user_pass2 = document.getElementById('account_password_conf'); | |
450 | user_email_label = document.getElementById('emaillabel'); | |
451 | user_email = document.getElementById('account_email'); | |
9680dd58 VP |
452 | user_fname = document.getElementById('account_fname'); |
453 | user_lname = document.getElementById('account_lname'); | |
454 | user_bio = document.getElementById('account_bio'); | |
f0106ef0 | 455 | |
78069032 VP |
456 | page4_back.addEventListener('click', e => { |
457 | page4.style.display = 'none'; | |
458 | page3.style.display = ''; | |
459 | }); | |
f0106ef0 | 460 | |
78069032 | 461 | page4_next.addEventListener('click', e => { |
f0106ef0 VP |
462 | |
463 | /* Form validation */ | |
464 | let req_not_met = ' <small style="color:red">Does not meet requirements</small>'; | |
465 | let errs = 0; | |
466 | const regex_username = /^[a-zA-Z\d]{3,}$/; | |
467 | if (!regex_username.test(user_name.value)) | |
468 | { | |
469 | user_name_label.innerHTML = 'Pick a username!' + req_not_met; | |
470 | errs++; | |
471 | } else | |
472 | user_name_label.innerHTML = 'Pick a username!'; | |
473 | ||
474 | let regex_pass = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]).{8,}$/; | |
475 | if (!regex_pass.test(user_pass.value)) | |
476 | { | |
477 | user_pass_label.innerHTML = 'Password' + req_not_met; | |
478 | errs++; | |
479 | } else | |
480 | user_pass_label.innerHTML = 'Password'; | |
481 | ||
482 | if (user_pass2.value !== user_pass.value) | |
483 | { | |
484 | user_pass2_label.innerHTML = 'Confirm password <small style="color:red">Passwords do not match</small>'; | |
485 | errs++; | |
486 | } else | |
487 | user_pass2_label.innerHTML = 'Confirm password'; | |
488 | ||
489 | const regex_email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | |
f0106ef0 VP |
490 | if (!regex_email.test(user_email.value)) |
491 | { | |
492 | user_email_label.innerHTML = 'Email address' + req_not_met; | |
493 | errs++; | |
494 | } | |
495 | else | |
496 | user_email_label.innerHTML = 'Email address'; | |
497 | ||
498 | if (errs) | |
9680dd58 | 499 | { |
54b9603c BM |
500 | e.preventDefault(); |
501 | return false; | |
9680dd58 VP |
502 | } |
503 | ||
78069032 | 504 | page4.style.display = 'none'; |
78069032 | 505 | }); |
eddacbaa BM |
506 | |
507 | function nextstep() | |
508 | { | |
509 | $('#db_overwrite_modal').modal('hide'); | |
224b44c8 BM |
510 | page3.style.display = 'none'; |
511 | page4.style.display = ''; | |
eddacbaa BM |
512 | window.scrollTo(0,0); |
513 | } | |
78069032 | 514 | </script> |