Correct login form handling

The user can simply press enter to login now
This commit is contained in:
2024-05-29 14:43:16 +01:00
parent ddc919bc83
commit fed9d0b9df
2 changed files with 28 additions and 10 deletions
+25 -7
View File
@@ -1,12 +1,11 @@
<div class="center">
<form id="login-form" action="submit">
<fieldset id="login-box-boundaries">
<legend>LOGIN</legend>
<div class="login-container">
<input class="tui-input" type="text" name="login-user" id="login-user"><br><br>
<input class="tui-input" type="password" name="login-pass" id="login-pass"><br><br>
<button type="button" id="login-submit-button">Login</button>
<button type="submit" id="login-submit-button">Login</button>
</div>
</fieldset>
</form>
@@ -14,11 +13,21 @@
{{ if .script }}
<script>
// Get a reference to the submit button
var submitBtn = document.getElementById("login-submit-button");
var loginForm = document.getElementById("login-form")
function handleSuccessfulPOST(data) {
const response = JSON.parse(data)
// Need to add something that acts when the password is wrong
// so that the user knows whats going on
if (response["state"] === "success") {
window.location.replace(window.location.origin + "/")
}
}
function handleForm(e) {
e.preventDefault();
// Add a click event listener to the submit button
submitBtn.addEventListener("click", function() {
// Get the login message from the textarea
var loginUser = document.getElementById("login-user").value;
var loginPass = document.getElementById("login-pass").value;
@@ -48,11 +57,20 @@
}
})
.then(data => {
window.location.replace(window.location.origin + "/")
// We should only do a refresh if the login is correct
handleSuccessfulPOST(data)
})
.catch(error => {
console.error(error);
});
}
loginForm.addEventListener("submit", (e) => {
handleForm(e);
});
// Allows to login by actuating the login button on the page
var submitBtn = document.getElementById("login-submit-button");
submitBtn.addEventListener("click", handleForm);
</script>
{{ end }}
+3 -3
View File
@@ -187,8 +187,8 @@ function customScroller() {
);
elem = document.getElementById("main-container-content");
document.addEventListener("keydown", (e) => {
const key = e.key;
// document.addEventListener("keydown", (e) => {
// const key = e.key;
// switch (key) {
// case 'j':
// elem.scrollBy(0, fontHeight);
@@ -209,7 +209,7 @@ function customScroller() {
// moveTab(-1)
// break;
// }
});
// });
}