login-template/web/createuser.html

51 lines
1.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>create user</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/createuser/css/style.css" rel="stylesheet">
</head>
<body>
create user
<form action="/createuser" method="post" class="login-form" id="login-form">
<div class="form-test">
<label for="name">Username: </label>
<input type="text" name="username" id="name" required />
</div>
<div class="form-test">
<label for="pass">Password: </label>
<input type="text" name="password" id="password" required />
</div>
<div class="form-test">
<input type="submit" value="Create user" />
</div>
</form>
<button id="logout-button">Log Out</button>
</body>
<script defer>
document.getElementById("login-form").addEventListener("submit", async (event) => {
event.preventDefault();
const username = event.target.username.value;
const password = event.target.password.value;
const token = await fetch("/createuser", {
method: "POST",
header: {"Content-Type": "application/json"},
body: JSON.stringify({username, password})
})
alert(await token.text());
});
document.getElementById("logout-button").addEventListener("click", async (event) => {
event.preventDefault();
const loggedout = await fetch("/logout", {
method: "POST"
});
alert(await loggedout.text());
});
</script>
</html>