implement user and login
This commit is contained in:
@@ -6,10 +6,29 @@ document.getElementById('login-btn').addEventListener('click', function () {
|
||||
alert("Bitte Benutzername und Passwort eingeben.");
|
||||
return;
|
||||
}
|
||||
fetch(`/unsecure/verify?username=${username}&pass=${password}`, { method: 'POST' })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
//console.log(data)
|
||||
window.location.href = data.route
|
||||
|
||||
// Beispiel: Zufällige User-ID generieren (normalerweise kommt das vom Server)
|
||||
const userid = Math.floor(Math.random() * 100000);
|
||||
});
|
||||
});
|
||||
document.getElementById('create-btn').addEventListener('click', function () {
|
||||
const username = document.getElementById('usrnm').value.trim();
|
||||
const password = document.getElementById('pw').value;
|
||||
if (!username || !password) {
|
||||
alert("Bitte Benutzername und Passwort eingeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Weiterleitung zur Startseite mit Parametern
|
||||
window.location.href = `/unsecure/?username=${encodeURIComponent(username)}&userid=${userid}`;
|
||||
});
|
||||
const result = confirm(`Möchtest du einen Nutzer mit ${username} erstellen?`);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
fetch(`/unsecure/register?username=${username}&pass=${password}`, { method: 'POST' })
|
||||
.then(res => res.json)
|
||||
.then(data => {
|
||||
console.log(data)
|
||||
})
|
||||
})
|
||||
@@ -138,3 +138,6 @@ function beansRefill(){
|
||||
function showCoffeeHistory(){
|
||||
window.location.href = "/unsecure/coffees-made";
|
||||
}
|
||||
function logout(){
|
||||
window.location.href = "/unsecure/login"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user