<!DOCTYPE html>
<html>
<head>
<script>
async function login(){
let response = await fetch('/login', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: document.getElementById('email').value,
password: document.getElementById('password').value,
})
});
if(response.ok){
let json = await response.json();
if(json.succeeded){
window.location.href = '/private_page';
}else{
alert(json.message);
}
}else{
alert(`${response.status} ${response.statusText}`); }
return false;
}
</script>
</head>
<body>
<p>Email: <input type="text" id="email"></p>
<p>Password: <input type="password" id="password"></p>
<button onclick="login()">Login</button>
</body>
</html>