forked from cehyman/BusSystemWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ejs
55 lines (50 loc) · 1.73 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Log In</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>Please Log In.</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>
<input id="buttonLogIn" type="button" value="Log In" /><br><br>
<a href="/createAccount">Don't have an account? Create one here.</a><br />
<script>
$(document).ready(function () {
$('#buttonLogIn').on('click', function () {
var inputUsername = document.getElementById("tUsername").value;
var inputPassword = document.getElementById("tPassword").value;
$.ajax({
url: "http://localhost:8080/loginRequest",
type: "POST",
data: {
username: inputUsername,
password: inputPassword,
},
dataType: 'json',
success: function (result) {
const LOGGEDIN = 0;
const ACCOUNT_DOESNT_EXIST = 1;
const INCORRECT_PASSWORD = 2;
if (result.code == LOGGEDIN) {
sessionStorage.setItem('username', inputUsername);
location.href = "/homePage";
} else if (result.code == ACCOUNT_DOESNT_EXIST) {
document.getElementById("labelLoginFailed").innerHTML = "Account with username '" + inputUsername + "' does not exist.";
} else if (result.code == INCORRECT_PASSWORD) {
document.getElementById("labelLoginFailed").innerHTML = "Incorrect password.";
} else {
document.getElementById("labelLoginFailed").innerHTML = "Error contacting database. error: " + result.code;
}
}
});
});
});
</script>
</body>
</html>