53 lines
1.7 KiB
HTML
53 lines
1.7 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Login (GET)</title>
|
|
<!-- Matcha.css -->
|
|
<link rel="stylesheet" href="matcha.css">
|
|
<main>
|
|
<h2>Login</h2>
|
|
<form method="POST" action="/is_authorized.php" id="login">
|
|
<label for="username">Navn</label>
|
|
<input id="navn" name="username" type="text" required>
|
|
|
|
<label for="password">Passord</label>
|
|
<input id="password" name="password" type="password" required>
|
|
<div class="flash danger" style="display: none;" id="feil">Feil passord</div>
|
|
|
|
<button type="submit">Log inn</button>
|
|
|
|
</form>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
|
|
|
|
<script>
|
|
let xmlHttpReq = new XMLHttpRequest();
|
|
xmlHttpReq.open("POST", "/is_authorized.php", false);
|
|
xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
|
|
xmlHttpReq.send("username=" + localStorage.getItem("navn")+"&"+"password=" + localStorage.getItem("passord"));
|
|
if (xmlHttpReq.status == 200){
|
|
window.location.replace("/admin.php");
|
|
}
|
|
|
|
document.forms["login"].addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
const resp = await fetch(event.target.action, {
|
|
method: "POST",
|
|
body: new URLSearchParams(new FormData(event.target)),
|
|
});
|
|
const status = await resp.status;
|
|
if (status == 200){
|
|
localStorage.setItem("navn", document.getElementById('navn').value);
|
|
localStorage.setItem("passord", document.getElementById('password').value);
|
|
window.location.replace("/admin.php");
|
|
}
|
|
else{
|
|
document.getElementById('feil').style.display = "block"
|
|
}
|
|
});
|
|
localStorage.setItem("name", "Chris");
|
|
</script> |