login-template/web/adminpanel.html

89 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<!--
struct ToggleRole {
perm: String,
value: bool,
username: String
}
-->
<head>
<title>perms toggle</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/css/style.css" rel="stylesheet">
</head>
<body>
<div id="data">
perms toggle
</div>
<form action="/toggleperms" method="post" class="permtoggle-form" id="permtoggle-form">
<div id="username-form">
<label for="name">Username: </label>
<input type="text" name="username" id="username" required />
</div>
<div id="load-button">
<input type="button" value="Load user" id="load-user" />
</div>
<div class="toggle-form">
<label for="admin-toggle">Admin: </label>
<input type="checkbox" value="admin-toggle" id="admin-toggle" />
<br>
<label for="make-post-toggle">Make posts: </label>
<input type="checkbox" value="make-post-toggle" id="make-post-toggle" />
<br>
<label for="comment-toggle">Comment: </label>
<input type="checkbox" value="comment-toggle" id="comment-toggle" />
</div>
</form>
</body>
<script defer>
document.getElementById("permtoggle-form").addEventListener("click", async (event) => {
event.preventDefault();
switch (event.srcElement.id) {
case "load-user": {
let username = document.getElementById("username").value;
const user = JSON.parse(await (await fetch(`/api/perms/${username}`)).text()).perms
if (user.Ok) {
document.querySelector(".toggle-form").style.display = "block"
document.getElementById("username-form").style.display = "none"
document.getElementById("load-button").style.display = "none"
document.getElementById("data").innerHTML = `Username: ${username}`
document.getElementById("admin-toggle").checked = user.Ok.admin
} else {
alert("User doesn't exist.")
}
break
}
// TODO: imlpement these, server handles perm checks
case "admin-toggle": {
// admin toggle
break
}
case "make-post-toggle": {
// make post toggle
break
}
case "comment-toggle": {
// comment toggle
break
}
}
// const user = await fetch("/api/perms/ ")
// const token = await fetch("/login", {
// method: "POST",
// header: {"Content-Type": "application/json"},
// body: JSON.stringify({username, password})
// })
// alert(await token.text());
});
</script>
</html>