From 1f3bc505a0c566014d154e23e73ee2faedae2ac8 Mon Sep 17 00:00:00 2001 From: derlole <122916573+derlole@users.noreply.github.com> Date: Thu, 15 May 2025 09:32:30 +0000 Subject: [PATCH] implement user and login --- db/user.db | Bin 8192 -> 8192 bytes {concept => obj}/user.py | 48 ++++++++++++-------------------------- routes/unsecure_routes.py | 42 +++++++++++++++++++++++++++++---- static/login.js | 29 +++++++++++++++++++---- static/script.js | 3 +++ templates/index.html | 4 ++-- templates/login.html | 2 +- 7 files changed, 82 insertions(+), 46 deletions(-) rename {concept => obj}/user.py (63%) diff --git a/db/user.db b/db/user.db index 7f464646b13c0e8e2027437f216fafa0a0a0eadd..172959d4615b52ddc7b27018365412cbe1d3f11b 100644 GIT binary patch delta 65 zcmZp0XmFSy&B#1a#+i|MW5N=C4krHl4E%5T?{5|qxXiD})q2Q)l|h(SFf%zLrIf$v Sz8x!rIInnON^WKzm;eB8XA@-r delta 28 kcmZp0XmFSy&B!=W#+i|EW5N=CCI*4cf&%CGCpPE+0C7+U 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}`; -}); \ No newline at end of file + 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) + }) +}) \ No newline at end of file diff --git a/static/script.js b/static/script.js index a8c2afc..d215af2 100644 --- a/static/script.js +++ b/static/script.js @@ -138,3 +138,6 @@ function beansRefill(){ function showCoffeeHistory(){ window.location.href = "/unsecure/coffees-made"; } +function logout(){ + window.location.href = "/unsecure/login" +} diff --git a/templates/index.html b/templates/index.html index 24ac754..9c56e41 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,8 +13,8 @@
gimmiCoffee
diff --git a/templates/login.html b/templates/login.html index 0c0f13f..821d202 100644 --- a/templates/login.html +++ b/templates/login.html @@ -16,7 +16,7 @@ - +