Password validation works but password is not shown in generated password thing
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
cami 2021-07-22 04:44:31 +02:00
parent c1fce5bf4a
commit a6346d7496
2 changed files with 37 additions and 18 deletions

View file

@ -1,23 +1,14 @@
import React, { useEffect, useState } from "react"; import React from "react";
import "../App.css"; import "../App.css";
export default function GeneratedPassword() { export default function GeneratedPassword() {
const [genPassword, setGenPassword] = useState("");
const genPassword = "PASSWORT_MANUELL"
const handleOnCopyEvent = (e) => { const handleOnCopyEvent = (e) => {
e.preventDefault(); e.preventDefault();
return false; return false;
}; };
useEffect(() => {
fetch("/api/protected/rcv_pw", {
method: "get",
}).then((response) => {
response.json().then((resp) => {
setGenPassword(resp.password);
});
});
}, []);
return ( return (
<> <>
<p onCopy={handleOnCopyEvent}> <p onCopy={handleOnCopyEvent}>

View file

@ -70,36 +70,64 @@ export default function Study() {
const handleOnPasteEvent = (e) => { const handleOnPasteEvent = (e) => {
e.preventDefault(); e.preventDefault();
console.log("paste not allowed");
return false; return false;
}; };
const checkIfUsernameIsCorrect = () => { const checkIfUsernameIsCorrect = () => {
console.log("serverUsername", serverUsername);
console.log("username", username);
if (serverUsername === username) { if (serverUsername === username) {
console.log("Passt soweit");
return true; return true;
} else { } else {
console.log("Passt gar nicht");
return false; 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 = () => { const checkIfValuesAreCorrect = () => {
checkIfUsernameIsCorrect(); checkIfUsernameIsCorrect();
checkIfPasswordIsCorrect();
console.log(checkIfPasswordIsCorrect());
if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect) {
return true;
} else {
alert("Passt nicht")
return false;
}
}; };
const handleClickAtStepStart = () => { const handleClickAtStepStart = () => {
setIsStepStart(false); setIsStepStart(false);
setIsStepNormal(true); setIsStepNormal(true);
handleLoggerOn(); handleLoggerOn();
receiveRandomPassword();
}; };
const handleClickAtStepNormal = () => { const handleClickAtStepNormal = () => {
checkIfValuesAreCorrect(); if (checkIfValuesAreCorrect()){
receiveRandomPassword();
setIsStepNormal(false); setIsStepNormal(false);
setIsStepPhone(true); setIsStepPhone(true);
}
}; };
const handleClickAtStepPhone = () => { const handleClickAtStepPhone = () => {