You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7 KiB

{{define "body"}}
<form id="frm-register" method="post" action="/login">
<label for="inp-secret">Registration-Key:</label>
<input id="inp-secret" name="secret" type="password" value=""/>
<button id="btn-submit">Request User</button>
</form>
<div class="hidden" id="general-info"></div>
<table class="hidden" id="user-data">
<tr>
<th>
Login:
</th>
<td><p id="login"></p></td>
</tr>
<tr>
<th>
Passwort:
</th>
<td><p id="passw"></p></td>
</tr>
</table>
{{end}}
{{define "scripts"}}
<script>
let frm = document.getElementById("frm-register");
let infoBox = document.getElementById("general-info");
let sbtn = document.getElementById("btn-submit");
const userData = document.getElementById("user-data");
const login = document.getElementById("login");
const passw = document.getElementById("passw");
frm.addEventListener("submit", async e => {
e.preventDefault();
let fd = new FormData(frm);
toggleDisabled(sbtn, "on");
setInfo(infoBox, "Processing Request...", "purple", "grey1");
toggleHidden(infoBox, "off");
const req = await fetch("/register", {
method: "POST",
body: new URLSearchParams({
secret: fd.get("secret")
}),
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
});
if (req.ok) {
const res = await req.text();
try {
const newUser = JSON.parse(res);
toggleHidden(userData, "off");
login.innerHTML = `${newUser.UID}`;
passw.innerHTML = `${newUser.Pass}`;
setInfo(infoBox, "Success", "green", "grey1");
setTimeout(() => {
toggleHidden(infoBox, "on");
}, 2000);
} catch (err) {
console.log(err);
setInfo(infoBox, "Failure (Could not parse JSON response)", "red", "grey1");
toggleHidden(infoBox, "off");
setTimeout(() => {
toggleHidden(infoBox, "on");
}, 2000);
}
} else {
setInfo(infoBox, "Failure", "red", "grey1");
toggleHidden(infoBox, "off");
setTimeout(() => {
toggleHidden(infoBox, "on");
}, 2000);
}
toggleDisabled(sbtn, "off");
})
</script>
<script src="/static/js/helper.js"></script>
{{end}}