This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.html
68 lines (56 loc) · 2.28 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
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login Page</h1>
<form id="loginForm">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<input type="submit" value="Login">
</form>
<!-- Hidden form - used for password manager prompt -->
<form id="hiddenForm" style="display: none;">
<input type="email" id="hiddenEmail" name="email">
<input type="password" id="hiddenPassword" name="password">
<input type="submit" value="Submit">
</form>
<script>
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the form from submitting
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const version = "9.0.0";
const API_BASE = "https://core.prd.analogio.dk";
const xhr = new XMLHttpRequest();
xhr.open("POST", API_BASE + "/api/v1/Account/login", true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
localStorage.setItem("authToken", data.token);
// Populate and submit the hidden form to trigger password save
document.getElementById("hiddenEmail").value = email;
document.getElementById("hiddenPassword").value = password;
document.getElementById("hiddenForm").submit();
window.location.href = "index.html";
} else {
console.error(`Failed with status: ${xhr.status}`);
}
}
};
xhr.send(JSON.stringify({
email,
password,
version
}));
});
</script>
</body>
</html>