2021-07-21 22:04:23 +02:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
2021-07-21 02:21:00 +02:00
|
|
|
import "../../App.css";
|
|
|
|
import Footer from "../../Footer";
|
|
|
|
import InputField from "../InputField";
|
|
|
|
import SubmitField from "../SubmitField";
|
|
|
|
import { Logger } from "@behametrics/logger-web";
|
2021-07-22 03:11:28 +02:00
|
|
|
import { Button } from "../Button";
|
2021-07-21 02:21:00 +02:00
|
|
|
import BehaviorStudyInfo from "../BehaviorStudyInfo";
|
|
|
|
import BehaviorNormal from "../BehaviorNormal";
|
2021-07-21 23:41:10 +02:00
|
|
|
import BehaviorPhone from "../BehaviorPhone";
|
|
|
|
import BehaviorStanding from "../BehaviorStanding";
|
2021-07-22 02:40:17 +02:00
|
|
|
import BehaviorStudyEnd from "../BehaviorStudyEnd";
|
2021-07-22 03:11:28 +02:00
|
|
|
import { authFetch } from "../../auth/AuthProvider";
|
2021-07-21 02:21:00 +02:00
|
|
|
|
|
|
|
export default function Study() {
|
2021-07-21 22:04:23 +02:00
|
|
|
const _logger = useRef(0);
|
2021-07-22 02:41:24 +02:00
|
|
|
const [serverUsername, setServerUsername] = useState("");
|
2021-07-21 21:53:57 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current = new Logger({
|
2021-07-21 21:53:57 +02:00
|
|
|
//inputs: ["cursor", "wheel", "keyboard", "touch"],
|
|
|
|
inputs: ["keyboard"],
|
|
|
|
// apiUrl: "https://behavior.marcocamenzind.ch",
|
|
|
|
apiUrl: "http://localhost:5000",
|
|
|
|
logToConsole: true,
|
|
|
|
});
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.init();
|
2021-07-22 03:11:28 +02:00
|
|
|
authFetch("/api/username", {
|
2021-07-22 02:41:24 +02:00
|
|
|
method: "get",
|
|
|
|
}).then((response) => {
|
|
|
|
response.json().then((resp) => {
|
2021-07-22 03:11:28 +02:00
|
|
|
setServerUsername(resp.username);
|
2021-07-22 02:41:24 +02:00
|
|
|
});
|
|
|
|
});
|
2021-07-21 21:53:57 +02:00
|
|
|
}, []);
|
|
|
|
|
2021-07-21 02:21:00 +02:00
|
|
|
let username = "";
|
|
|
|
const setUsername = (tmp_username) => {
|
|
|
|
username = tmp_username;
|
|
|
|
};
|
|
|
|
|
|
|
|
let password = "";
|
|
|
|
const setPassword = (tmp_password) => {
|
|
|
|
password = tmp_password;
|
|
|
|
};
|
|
|
|
|
2021-07-21 21:53:57 +02:00
|
|
|
const [isStepStart, setIsStepStart] = useState(true);
|
|
|
|
const [isStepNormal, setIsStepNormal] = useState(false);
|
2021-07-21 23:41:10 +02:00
|
|
|
const [isStepPhone, setIsStepPhone] = useState(false);
|
|
|
|
const [isStepStanding, setIsStepStanding] = useState(false);
|
|
|
|
const [isStepEnd, setIsStepEnd] = useState(false);
|
2021-07-21 02:21:00 +02:00
|
|
|
|
|
|
|
const handleLoggerOff = () => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.stop();
|
2021-07-21 02:21:00 +02:00
|
|
|
console.log("Logger ausgeschaltet");
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLoggerOn = () => {
|
2021-07-21 22:04:23 +02:00
|
|
|
_logger.current.start();
|
2021-07-21 02:21:00 +02:00
|
|
|
console.log("start logging ");
|
|
|
|
};
|
|
|
|
|
|
|
|
const handlePasswordChange = (e) => {
|
|
|
|
setPassword(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleUsernameChange = (e) => {
|
|
|
|
setUsername(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleOnPasteEvent = (e) => {
|
|
|
|
e.preventDefault();
|
2021-07-22 04:44:31 +02:00
|
|
|
console.log("paste not allowed");
|
2021-07-21 02:21:00 +02:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2021-07-22 03:11:28 +02:00
|
|
|
const checkIfUsernameIsCorrect = () => {
|
|
|
|
if (serverUsername === username) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-22 16:53:08 +02:00
|
|
|
const [genPassword, setGenPassword] = useState("");
|
2021-07-22 04:44:31 +02:00
|
|
|
|
|
|
|
const receiveRandomPassword = () => {
|
|
|
|
fetch("/api/rcv_pw", {
|
|
|
|
method: "get",
|
|
|
|
}).then((response) => {
|
|
|
|
response.json().then((resp) => {
|
2021-07-22 16:53:08 +02:00
|
|
|
console.log(resp.random_password);
|
|
|
|
setGenPassword(resp.random_password);
|
|
|
|
console.log("rcv pw; print genPassword", genPassword);
|
2021-07-22 04:44:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const checkIfPasswordIsCorrect = () => {
|
2021-07-22 16:53:08 +02:00
|
|
|
if (genPassword === password) {
|
2021-07-22 04:44:31 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2021-07-22 03:11:28 +02:00
|
|
|
|
|
|
|
const checkIfValuesAreCorrect = () => {
|
2021-07-22 04:44:31 +02:00
|
|
|
console.log(checkIfPasswordIsCorrect());
|
2021-07-22 16:53:08 +02:00
|
|
|
if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect()) {
|
2021-07-22 04:44:31 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2021-07-22 05:20:37 +02:00
|
|
|
alert("Passt nicht");
|
2021-07-22 04:44:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-22 02:41:24 +02:00
|
|
|
};
|
|
|
|
|
2021-07-21 23:41:10 +02:00
|
|
|
const handleClickAtStepStart = () => {
|
2021-07-22 16:53:08 +02:00
|
|
|
receiveRandomPassword();
|
2021-07-21 04:33:52 +02:00
|
|
|
setIsStepStart(false);
|
|
|
|
setIsStepNormal(true);
|
2021-07-21 22:38:31 +02:00
|
|
|
handleLoggerOn();
|
2021-07-21 04:33:52 +02:00
|
|
|
};
|
|
|
|
|
2021-07-21 23:41:10 +02:00
|
|
|
const handleClickAtStepNormal = () => {
|
2021-07-22 05:20:37 +02:00
|
|
|
if (checkIfValuesAreCorrect()) {
|
2021-07-22 04:44:31 +02:00
|
|
|
receiveRandomPassword();
|
|
|
|
setIsStepNormal(false);
|
|
|
|
setIsStepPhone(true);
|
|
|
|
}
|
2021-07-21 23:41:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickAtStepPhone = () => {
|
2021-07-22 16:53:08 +02:00
|
|
|
if (checkIfValuesAreCorrect()){
|
|
|
|
receiveRandomPassword();
|
2021-07-21 23:41:10 +02:00
|
|
|
setIsStepPhone(false);
|
|
|
|
setIsStepStanding(true);
|
2021-07-22 16:53:08 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("Passwort und Benutzername stimmen nicht.")
|
|
|
|
}
|
2021-07-21 23:41:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickAtStepStanding = () => {
|
2021-07-22 16:53:08 +02:00
|
|
|
if (checkIfValuesAreCorrect()){
|
2021-07-21 23:41:10 +02:00
|
|
|
setIsStepStanding(false);
|
|
|
|
setIsStepEnd(true);
|
|
|
|
handleLoggerOff();
|
2021-07-22 16:53:08 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("Passwort und Benutzername stimmen nicht.")
|
|
|
|
}
|
2021-07-21 23:41:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const study_start = (
|
|
|
|
<>
|
|
|
|
<BehaviorStudyInfo />
|
|
|
|
<Button
|
|
|
|
className="btns"
|
|
|
|
buttonStyle="btn--primary"
|
|
|
|
buttonSize="btn--full"
|
|
|
|
onClick={handleClickAtStepStart}
|
|
|
|
newTo="study"
|
|
|
|
>
|
2021-07-22 07:29:54 +02:00
|
|
|
Studie starten
|
2021-07-21 23:41:10 +02:00
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_normal = (
|
|
|
|
<>
|
2021-07-22 05:20:37 +02:00
|
|
|
<BehaviorNormal genPassword={_genPassword.current} />
|
2021-07-21 23:41:10 +02:00
|
|
|
<form id="behaviorNormal">
|
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Weiter zur nächsten Situation"
|
|
|
|
InputValue="next-situation"
|
|
|
|
InputName="Weiter"
|
|
|
|
onClick={handleClickAtStepNormal}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_phone = (
|
|
|
|
<>
|
|
|
|
<BehaviorPhone />
|
|
|
|
<form id="behaviorPhone">
|
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Weiter zur nächsten Situation"
|
|
|
|
InputValue="next-situation"
|
|
|
|
InputName="Weiter"
|
|
|
|
onClick={handleClickAtStepPhone}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const study_standing = (
|
|
|
|
<>
|
|
|
|
<BehaviorStanding />
|
2021-07-22 02:40:58 +02:00
|
|
|
<form id="behaviorStanding">
|
2021-07-21 23:41:10 +02:00
|
|
|
<InputField
|
|
|
|
LabelName="Benutzername"
|
|
|
|
onChange={handleUsernameChange}
|
|
|
|
InputType="text"
|
|
|
|
InputName="Benutzername"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
InputType="password"
|
|
|
|
InputName="Passwort"
|
|
|
|
InputPlaceHolder="Benutzername"
|
|
|
|
onPaste={handleOnPasteEvent}
|
|
|
|
/>
|
|
|
|
<SubmitField
|
|
|
|
LabelName="Studie beenden"
|
|
|
|
InputValue="stopStudy"
|
|
|
|
InputName="quit"
|
|
|
|
onClick={handleClickAtStepStanding}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2021-07-22 02:40:17 +02:00
|
|
|
const study_end = <BehaviorStudyEnd />;
|
2021-07-21 23:41:10 +02:00
|
|
|
|
2021-07-21 02:21:00 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="sitePage">
|
|
|
|
<h1>Studie</h1>
|
2021-07-21 23:41:10 +02:00
|
|
|
{isStepStart ? study_start : null}
|
|
|
|
{isStepNormal ? study_normal : null}
|
|
|
|
{isStepPhone ? study_phone : null}
|
|
|
|
{isStepStanding ? study_standing : null}
|
|
|
|
{isStepEnd ? study_end : null}
|
2021-07-21 02:21:00 +02:00
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|