blink/frontend/vanilla/html/login.html

73 lines
1.9 KiB
HTML
Raw Normal View History

2023-09-27 12:18:29 +02:00
<!DOCTYPE html>
2024-03-04 16:49:36 +01:00
<html lang="en">
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
<head>
<meta charset="UTF-8">
<title>Log in - Blink</title>
<link rel="stylesheet" href="../css/login-register.css">
</head>
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
<body>
<!-- partial:index.partial.html -->
<div id="login-form-wrap">
<h2>Login</h2>
<form id="login-form" method="POST">
<p>
<input type="email" id="email" name="email" placeholder="Email Address" required><i
class="validation"><span></span><span></span></i>
</p>
<p>
<input type="password" id="password" name="password" placeholder="Password" required><i
class="validation"><span></span><span></span></i>
</p>
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
<p>
<button type="button" onclick="login()">Login</button>
</p>
</form>
<div id="create-account-wrap">
<p>Not a member? <a href="./register.html">Create Account</a>
2023-10-18 15:36:43 +02:00
<p>
</div>
2024-03-04 16:49:36 +01:00
</div>
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
<script src="../js/constants.js"></script>
2024-03-21 09:36:16 +01:00
<script src="../js/utils.js"></script>
2024-03-04 16:49:36 +01:00
<script>
async function login() {
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
if (!email || !password) {
alert('Please fill in all fields');
return;
}
2024-03-06 10:19:37 +01:00
const response = await fetch(`${API_URL}/persons/me/token`, {
2024-03-04 16:49:36 +01:00
method: "POST",
body: JSON.stringify({
email: email,
password: password
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
2023-10-18 15:36:43 +02:00
}
2024-03-04 16:49:36 +01:00
});
2023-10-18 15:36:43 +02:00
2024-03-04 16:49:36 +01:00
const data = await response.json();
2024-02-28 15:13:19 +01:00
2024-03-04 16:49:36 +01:00
if (response.ok) {
console.log(`Login was successful. Token is ${data.token}`);
document.cookie = `token=${data.token};`;
2024-03-06 10:19:37 +01:00
window.location.href = 'userprofile.html?id=me';
2024-03-04 16:49:36 +01:00
} else {
2024-03-21 09:36:16 +01:00
alert(data.error);
//callbackErrors(data.errors, alert);
2024-02-28 12:08:00 +01:00
}
2024-03-04 16:49:36 +01:00
}
</script>
</body>
2023-10-18 15:36:43 +02:00
2024-02-28 12:08:00 +01:00
</html>