-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.html
184 lines (149 loc) · 6.29 KB
/
login.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SWSRP Login Page</title>
<link rel="icon" href="./favicon.ico">
<!--BOOTSTRAP CDN-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<!--FAVICON-->
<link rel="icon" type="image/x-icon" href="./static/images/landing-1">
<!--CUSTOM STYLE LINKS-->
<link rel="stylesheet" href="./static/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- CUSTOM JS scripts -->
<script type="text/javascript" src="./static/js/script.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<script>
// endpoints
const baseUrl = 'http://localhost:8000/api';
// authentication
const loginToken = '/token/';
const loginRefresh = '/token/refresh/';
const api = axios.create({
timeout: 30000 // in ms
});
// functions
function getEndpoint(baseUrl, endpoint) {
return baseUrl + endpoint + '?format=json';
}
function updateRouteAlert(alertType, message) {
const routeAlert = document.getElementById("login-alert");
routeAlert.innerHTML = `<div class='alert alert-${alertType} alert-dismissible fade show' role='alert'>${message}<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>`;
}
function authenticateUser() {
const endpoint = getEndpoint(baseUrl, loginToken);
const usrname = document.getElementById("username").value;
const passwd = document.getElementById("password").value;
api.post(endpoint, {
username: usrname,
password: passwd
})
.then(function (response) {
console.log(response.data);
if (response.status == 200) {
setAuthTokenCookie(response.data.access);
updateRouteAlert("success", "User logged in!");
// fix redirect repo-name bug if hosted on github pages
window.location.href = "./";
}
})
.catch(function (error) {
// If the error is a 401 error, update alert
if (error.response && error.response.status == 401) {
updateRouteAlert("danger", "Invalid Credentials!!");
} else {
// Handle other errors
updateRouteAlert("warning", "Error!! Check console for more information!")
console.error(error);
}
})
.finally(function () {
return false;
})
}
</script>
<style>
html,
body {
height: 100%;
}
body {
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.form-signin .checkbox {
font-weight: 400;
}
.form-signin .form-floating:focus-within {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
</head>
<body class="text-center">
<main class="form-signin">
<div class="container" id="login-alert">
</div>
<div>
<img class="mb-4 img-fluid" src="./static/images/logo.png" alt="Logo">
<p class="h3 mb-4 fw-bold">Sign In to access</p>
<p class="h5 mb-4 fw-normal">SWSRP Login Page</p>
<div class="form-floating">
<input type="text" name="username" class="form-control" id="username" placeholder="johndoe">
<label for="floatingInput">Username</label>
</div>
<div class="form-floating">
<input type="password" name="password" class="form-control" id="password" placeholder="userpass">
<label for="floatingPassword">Password</label>
</div>
<button class="w-100 btn btn-lg btn-primary" id="login-button" onclick="authenticateUser()">Sign
in</button>
</div>
</main>
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
</body>
</html>