simpleauth/static/login.html

57 lines
1.4 KiB
HTML
Raw Normal View History

2021-08-15 11:03:25 -06:00
<!DOCTYPE html>
<html>
2022-03-05 17:46:12 -07:00
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<style>
html {
font-family: sans-serif;
color: white;
background: seagreen linear-gradient(315deg, rgba(255,255,255,0.4), transparent);
}
body {
height: 100vh;
}
div {
margin: 1em;
}
#error {
color: red;
}
</style>
<script>
function error(msg) {
document.querySelector("#error").textContent = msg
}
async function login(evt) {
evt.preventDefault()
let req = await fetch(evt.target.action, {
method: evt.target.method,
body: new FormData(evt.target),
credentials: "same-origin",
})
if (! req.ok) {
error(req.statusText || "Authentication failed")
return
}
window.location = window.location
}
function init() {
document.querySelector("form").addEventListener("submit", login)
}
window.addEventListener("load", init)
</script>
</head>
<body>
<h1>Log In</h1>
<form action="/" method="post">
<div>Password: <input type="password" name="passwd"></div>
<div><input type="submit" value="Log In"></div>
</form>
<div id="error"></div>
</body>
</html>