AppFlowy-Cloud/admin_frontend/templates/login.html

61 lines
1.7 KiB
HTML

<!doctype html>
<html lang="en">
<body>
<h1>Admin Login</h1>
<form id="loginForm">
<table>
<tr>
<td>
<label for="email">Email:</label>
</td>
<td>
<input type="text" id="email" name="email" required />
</td>
</tr>
<tr>
<td>
<label for="password">Password:</label>
</td>
<td>
<input type="password" id="password" name="password" required />
</td>
</tr>
</table>
<button type="button" id="submitBtn">Submit</button>
</form>
<div id="response"></div>
<script>
document
.getElementById("submitBtn")
.addEventListener("click", function () {
var data = {
email: document.getElementById("email").value,
password: document.getElementById("password").value,
};
fetch("/web-api/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
credentials: "same-origin",
})
.then((response) => {
if (!response.ok) {
// If HTTP status code is not OK, throw an error with the status text
throw Error(response.statusText);
}
window.location.href = "/web/home";
})
.catch((error) => {
console.error(`Error:, ${error}`);
document.getElementById(
"response",
).innerText = `Login failed: ${error.message}`;
});
});
</script>
</body>
</html>