commit 18/12/2025

This commit is contained in:
2025-12-18 16:56:48 +07:00
parent bdb24a7c03
commit 8e2d529a9e
7 changed files with 226 additions and 159 deletions

View File

@@ -0,0 +1,54 @@
function cleartext() {
$('#usernametext').val('');
$('#passwordtext').val('');
}
function validstring(str) {
if (str !== null && str.length > 0) {
return true;
}
return false;
}
$(document).ready(function () {
console.log("Login page is ready.");
cleartext();
$('#loginbtn').off('click').on('click', function () {
var username = $('#usernametext').val();
var password = $('#passwordtext').val();
if (!validstring(username) || !validstring(password)) {
alert("Please enter both username and password.");
cleartext();
return;
}
fetch('/login.html', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
username: username,
password: password
})
})
.then(response => {
//console.log("Received response from server : " + response.status + " " + response.statusText+" is redirected: "+response.redirected);
if (response.redirected) {
//alert("Login successful, will redirect now.");
//console.log("Redirecting to: " + response.url);
window.location.href = response.url;
return;
}
if (response.status === 400 || response.status === 401) {
alert("Login failed");
cleartext();
}
})
.catch(error => {
console.error('Error:', error);
alert("An error occurred during login.");
cleartext();
});
});
});