From a6346d749652420d7c9b76b4977830bc0652334d Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 04:44:31 +0200 Subject: [PATCH] Password validation works but password is not shown in generated password thing --- frontend/src/components/GeneratedPassword.js | 13 +----- frontend/src/components/pages/Study.js | 42 ++++++++++++++++---- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/GeneratedPassword.js b/frontend/src/components/GeneratedPassword.js index c963b5c..af03882 100644 --- a/frontend/src/components/GeneratedPassword.js +++ b/frontend/src/components/GeneratedPassword.js @@ -1,23 +1,14 @@ -import React, { useEffect, useState } from "react"; +import React from "react"; import "../App.css"; export default function GeneratedPassword() { - const [genPassword, setGenPassword] = useState(""); + const genPassword = "PASSWORT_MANUELL" const handleOnCopyEvent = (e) => { e.preventDefault(); return false; }; - useEffect(() => { - fetch("/api/protected/rcv_pw", { - method: "get", - }).then((response) => { - response.json().then((resp) => { - setGenPassword(resp.password); - }); - }); - }, []); return ( <>

diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 7e849d1..094479f 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -70,36 +70,64 @@ export default function Study() { const handleOnPasteEvent = (e) => { e.preventDefault(); + console.log("paste not allowed"); return false; }; const checkIfUsernameIsCorrect = () => { - console.log("serverUsername", serverUsername); - console.log("username", username); if (serverUsername === username) { - console.log("Passt soweit"); return true; } else { - console.log("Passt gar nicht"); return false; } }; + const _genPassword = useRef(null); + + const receiveRandomPassword = () => { + fetch("/api/rcv_pw", { + method: "get", + }).then((response) => { + response.json().then((resp) => { + _genPassword.current = resp.random_password; + console.log(_genPassword.current) + }); + }); + }; + + const checkIfPasswordIsCorrect = () => { + if (_genPassword.current === password) { + return true; + } else { + return false; + } + }; const checkIfValuesAreCorrect = () => { checkIfUsernameIsCorrect(); + checkIfPasswordIsCorrect(); + console.log(checkIfPasswordIsCorrect()); + if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect) { + return true; + } else { + alert("Passt nicht") + return false; + } }; const handleClickAtStepStart = () => { setIsStepStart(false); setIsStepNormal(true); handleLoggerOn(); + receiveRandomPassword(); }; const handleClickAtStepNormal = () => { - checkIfValuesAreCorrect(); - setIsStepNormal(false); - setIsStepPhone(true); + if (checkIfValuesAreCorrect()){ + receiveRandomPassword(); + setIsStepNormal(false); + setIsStepPhone(true); + } }; const handleClickAtStepPhone = () => {