From ef1358baa4d20776e66a8cdd24ee9d3c51aabf6a Mon Sep 17 00:00:00 2001 From: brausjonas Date: Tue, 16 May 2023 19:52:58 +0200 Subject: [PATCH] OnLoginClick Logic Fetch data from the backend and save the session id to the local storage --- anwendung/src/components/Login.jsx | 33 ++- backend/database.mv.db | Bin 36864 -> 45056 bytes backend/database.trace.db | 246 ++++++++++++++++++ .../anwprj/Users/UserSessionIDHandler.java | 2 +- 4 files changed, 274 insertions(+), 7 deletions(-) diff --git a/anwendung/src/components/Login.jsx b/anwendung/src/components/Login.jsx index f1416fc..227d693 100644 --- a/anwendung/src/components/Login.jsx +++ b/anwendung/src/components/Login.jsx @@ -5,17 +5,32 @@ export default function Login() { let url = "http://localhost:8080/users" - function on_login_click() - { + async function on_login_click() { url += "?mail=" + inputUserName + "&password=" + inputPassword; - fetch(url, { + let response = await fetch(url, { method: "GET", - }).then(r => console.log()) + }); + + let reader = response.body.getReader(); + let value = String.fromCharCode.apply(null, ((await reader.read()).value)) + if(value != "failed") + { + localStorage.setItem("sessionid", value) + } + else + { + setInputPassword(""); + setInputUserName(""); + setHint("wrong login credentials") + setBackgroundColor("rgb(171,89,89)") + } } const [inputUserName, setInputUserName] = useState("") const [inputPassword, setInputPassword] = useState("") + const [hint, setHint] = useState("type here") + const [backgroundColor, setBackgroundColor] = useState("rgb(255, 255, 255)") return (
@@ -24,10 +39,16 @@ export default function Login() {

Username

- setInputUserName(e.target.value)} placeholder="Type here" className="input input-bordered input-sm w-full max-w-xs"/> + setInputUserName(e.target.value)} placeholder={hint} className="input input-bordered input-sm w-full max-w-xs" + style={{ + backgroundColor: backgroundColor + }}/>

Password

- setInputPassword(e.target.value)} placeholder="Type here" className="input input-bordered input-sm w-full max-w-xs"/> + setInputPassword(e.target.value)} placeholder={hint} className="input input-bordered input-sm w-full max-w-xs" + style={{ + backgroundColor: backgroundColor + }}/>