63 lines
1.7 KiB
HTML
63 lines
1.7 KiB
HTML
<div class="center">
|
|
<form
|
|
id="login-form"
|
|
action="submit"
|
|
hx-post="/send-login"
|
|
hx-swap="innerHTML"
|
|
hx-target="#req-result">
|
|
|
|
<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="submit" id="login-submit-button">Login</button>
|
|
</div>
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
|
|
{{ if .script }}
|
|
<script>
|
|
// Get a reference to the submit button
|
|
var submitBtn = document.getElementById("login-submit-button");
|
|
|
|
// 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;
|
|
|
|
// Create the JSON object to send
|
|
var jsonData = {
|
|
username: loginUser,
|
|
password: loginPass,
|
|
};
|
|
|
|
// Configure the fetch request
|
|
fetch("/send-login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify(jsonData)
|
|
})
|
|
.then(response => {
|
|
// Check if the response is OK
|
|
if (response.ok) {
|
|
// Request was successful, handle response if needed
|
|
return response.text();
|
|
} else {
|
|
// Request failed, handle error if needed
|
|
throw new Error("Error: " + response.statusText);
|
|
}
|
|
})
|
|
.then(data => {
|
|
window.location.replace(window.location.origin + "/")
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
});
|
|
</script>
|
|
{{ end }} |