-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
55 lines (53 loc) · 1.57 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Authentication Page</title>
<script>
window.onload = function () {
document
.querySelector("form")
.addEventListener("submit", function (event) {
event.preventDefault();
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
fetch("http://localhost:8000/token", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
username: username,
password: password,
}),
})
.then((response) => response.json())
.then((data) => {
alert("Login Successful");
console.log(data);
if (data.access_token) {
sessionStorage.setItem("token", data.access_token);
}
})
.catch((error) => {
console.error("Error:", error);
});
});
};
</script>
</head>
<body>
<h1>Login</h1>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required /><br /><br />
<label for="password">Password:</label>
<input
type="password"
id="password"
name="password"
required
/><br /><br />
<input type="submit" value="Login" />
</form>
</body>
</html>