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);
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 = (