From 2f7d733591c86af1aa905b782aba83cbbd4ecfe4 Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 16:53:08 +0200 Subject: [PATCH] Receive password and check if it's the same --- frontend/src/components/pages/Study.js | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 99fcff9..a0f9df1 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -82,28 +82,22 @@ export default function Study() { } }; - const _genPassword = useRef(null); - let genPassword = ""; - - const setGenPassword = (tmp) => { - genPassword = tmp; - console.log("setGenPassword", genPassword, tmp); - }; + const [genPassword, setGenPassword] = useState(""); const receiveRandomPassword = () => { fetch("/api/rcv_pw", { method: "get", }).then((response) => { response.json().then((resp) => { - _genPassword.current = resp.random_password; - console.log(_genPassword.current); - setGenPassword(_genPassword.current); + console.log(resp.random_password); + setGenPassword(resp.random_password); + console.log("rcv pw; print genPassword", genPassword); }); }); }; const checkIfPasswordIsCorrect = () => { - if (_genPassword.current === password) { + if (genPassword === password) { return true; } else { return false; @@ -111,10 +105,8 @@ export default function Study() { }; const checkIfValuesAreCorrect = () => { - checkIfUsernameIsCorrect(); - checkIfPasswordIsCorrect(); console.log(checkIfPasswordIsCorrect()); - if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect) { + if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect()) { return true; } else { alert("Passt nicht"); @@ -123,10 +115,10 @@ export default function Study() { }; const handleClickAtStepStart = () => { + receiveRandomPassword(); setIsStepStart(false); setIsStepNormal(true); handleLoggerOn(); - receiveRandomPassword(); }; const handleClickAtStepNormal = () => { @@ -138,14 +130,25 @@ export default function Study() { }; const handleClickAtStepPhone = () => { + if (checkIfValuesAreCorrect()){ + receiveRandomPassword(); setIsStepPhone(false); setIsStepStanding(true); + } + else { + console.log("Passwort und Benutzername stimmen nicht.") + } }; const handleClickAtStepStanding = () => { + if (checkIfValuesAreCorrect()){ setIsStepStanding(false); setIsStepEnd(true); handleLoggerOff(); + } + else { + console.log("Passwort und Benutzername stimmen nicht.") + } }; const study_start = (