forked from cehyman/BusSystemWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateAccount.ejs
59 lines (53 loc) · 1.97 KB
/
createAccount.ejs
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
<!DOCTYPE html>
<html>
<head>
<title>Create Account</title>
<link rel="stylesheet" href="style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>Create an Account.</h1>
<label class="redLabel" id="labelLoginFailed"></label><br />
<label>Username:</label>
<input id="tUsername" type="text"><br><br>
<label>Password:</label>
<input id="tPassword" type="password"><br><br>
<label id="labelConfirm">Confirm Password:</label>
<input id="tConfirmPassword" type="password"><br><br>
<input id="buttonCreateAccount" type="button" value="Create Account" /><br><br>
<a href="/index">Have an account? Log in here.</a><br />
<script>
$(document).ready(function () {
$('#buttonCreateAccount').on('click', function () {
var inputUsername = document.getElementById("tUsername").value;
var inputPassword = document.getElementById("tPassword").value;
var inputConfirmPass = document.getElementById("tConfirmPassword").value;
if (inputPassword == inputConfirmPass) {
$.ajax({
url: "http://localhost:8080/createAccountRequest",
type: "POST",
data: {
username: inputUsername,
password: inputPassword,
},
dataType: 'json',
success: function (result) {
const ACCOUNT_EXISTS = 0;
const CREATED_ACCOUNT = 1;
if (result.code == ACCOUNT_EXISTS) {
document.getElementById("labelLoginFailed").innerHTML = "Account with username '" + inputUsername + "' already exists";
} else if (result.code == CREATED_ACCOUNT) {
document.getElementById("labelLoginFailed").innerHTML = "Created account with username '" + inputUsername + "'";
} else {
document.getElementById("labelLoginFailed").innerHTML = "Error contacting database. error: " + result.code;
}
}
});
} else {
document.getElementById("labelLoginFailed").innerHTML = "Passwords do not match.";
}
});
});
</script>
</body>
</html>