Implement server-side authentication and update login UI texts

This commit is contained in:
2025-01-24 21:54:05 +01:00
parent 1edcefbd64
commit da2f568acf
4 changed files with 44 additions and 13 deletions

View File

@@ -29,15 +29,27 @@ document.addEventListener('DOMContentLoaded', function() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Simple authentication check (replace with your own logic)
if (username === 'fredrik' && password === 'apa') {
sessionStorage.setItem('loggedIn', 'true');
loginContainer.style.display = 'none';
appContainer.style.display = 'block';
loadTags();
} else {
loginMessage.textContent = 'Invalid username or password';
}
// Send credentials to the server for validation
fetch('/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(username + ':' + password)
}
})
.then(response => {
if (response.ok) {
sessionStorage.setItem('loggedIn', 'true');
loginContainer.style.display = 'none';
appContainer.style.display = 'block';
loadTags();
} else {
loginMessage.textContent = 'Invalid username or password';
}
})
.catch(error => {
loginMessage.textContent = 'Error logging in';
});
});
document.getElementById('taskForm').addEventListener('submit', function(e) {