Receive password and check if it's the same

This commit is contained in:
cami 2021-07-22 16:53:08 +02:00
parent f5e58ccb09
commit 2f7d733591

View file

@ -82,28 +82,22 @@ export default function Study() {
} }
}; };
const _genPassword = useRef(null); const [genPassword, setGenPassword] = useState("");
let genPassword = "";
const setGenPassword = (tmp) => {
genPassword = tmp;
console.log("setGenPassword", genPassword, tmp);
};
const receiveRandomPassword = () => { const receiveRandomPassword = () => {
fetch("/api/rcv_pw", { fetch("/api/rcv_pw", {
method: "get", method: "get",
}).then((response) => { }).then((response) => {
response.json().then((resp) => { response.json().then((resp) => {
_genPassword.current = resp.random_password; console.log(resp.random_password);
console.log(_genPassword.current); setGenPassword(resp.random_password);
setGenPassword(_genPassword.current); console.log("rcv pw; print genPassword", genPassword);
}); });
}); });
}; };
const checkIfPasswordIsCorrect = () => { const checkIfPasswordIsCorrect = () => {
if (_genPassword.current === password) { if (genPassword === password) {
return true; return true;
} else { } else {
return false; return false;
@ -111,10 +105,8 @@ export default function Study() {
}; };
const checkIfValuesAreCorrect = () => { const checkIfValuesAreCorrect = () => {
checkIfUsernameIsCorrect();
checkIfPasswordIsCorrect();
console.log(checkIfPasswordIsCorrect()); console.log(checkIfPasswordIsCorrect());
if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect) { if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect()) {
return true; return true;
} else { } else {
alert("Passt nicht"); alert("Passt nicht");
@ -123,10 +115,10 @@ export default function Study() {
}; };
const handleClickAtStepStart = () => { const handleClickAtStepStart = () => {
receiveRandomPassword();
setIsStepStart(false); setIsStepStart(false);
setIsStepNormal(true); setIsStepNormal(true);
handleLoggerOn(); handleLoggerOn();
receiveRandomPassword();
}; };
const handleClickAtStepNormal = () => { const handleClickAtStepNormal = () => {
@ -138,14 +130,25 @@ export default function Study() {
}; };
const handleClickAtStepPhone = () => { const handleClickAtStepPhone = () => {
if (checkIfValuesAreCorrect()){
receiveRandomPassword();
setIsStepPhone(false); setIsStepPhone(false);
setIsStepStanding(true); setIsStepStanding(true);
}
else {
console.log("Passwort und Benutzername stimmen nicht.")
}
}; };
const handleClickAtStepStanding = () => { const handleClickAtStepStanding = () => {
if (checkIfValuesAreCorrect()){
setIsStepStanding(false); setIsStepStanding(false);
setIsStepEnd(true); setIsStepEnd(true);
handleLoggerOff(); handleLoggerOff();
}
else {
console.log("Passwort und Benutzername stimmen nicht.")
}
}; };
const study_start = ( const study_start = (