From 959912bd9b0eaac3b59d75a1024766be5aff4aca Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 02:40:17 +0200 Subject: [PATCH 01/11] Refactored so that the studyEnd also has its own component --- frontend/src/components/BehaviorStudyEnd.js | 12 ++++++++++++ frontend/src/components/pages/Study.js | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/BehaviorStudyEnd.js diff --git a/frontend/src/components/BehaviorStudyEnd.js b/frontend/src/components/BehaviorStudyEnd.js new file mode 100644 index 0000000..e19c613 --- /dev/null +++ b/frontend/src/components/BehaviorStudyEnd.js @@ -0,0 +1,12 @@ +import React from "react"; +import "../App.css"; + +export default function BehaviorStudyEnd() { + return ( + <> +

+ Merci :-) +

+ + ); +} diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 9378c54..4d73609 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -9,6 +9,7 @@ import BehaviorNormal from "../BehaviorNormal"; import { Button } from "../Button"; import BehaviorPhone from "../BehaviorPhone"; import BehaviorStanding from "../BehaviorStanding"; +import BehaviorStudyEnd from "../BehaviorStudyEnd"; export default function Study() { const _logger = useRef(0); @@ -215,7 +216,7 @@ export default function Study() { ); - const study_end =

Merci :-)

; + const study_end = ; return ( <> From e7407fd40b6ba754a84d53958c2957d5927a7012 Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 02:40:58 +0200 Subject: [PATCH 02/11] Refactoring and removing unused things --- backend/src/app.py | 1 - frontend/src/components/pages/Study.js | 27 +------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/backend/src/app.py b/backend/src/app.py index 6d9b201..62be6d7 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -134,7 +134,6 @@ def protected(): @app.route('/api/protected/rcv_pw', methods=['GET']) -# @flask_praetorian.auth_required def get_password(): pw = get_random_password() ret = {'password': pw} diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 4d73609..c5247c9 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -68,7 +68,6 @@ export default function Study() { setIsStepStart(false); setIsStepNormal(true); handleLoggerOn(); - // forceUpdate(); }; const handleClickAtStepNormal = () => { @@ -87,30 +86,6 @@ export default function Study() { handleLoggerOff(); }; - const onSubmitClick = (e) => { - e.preventDefault(); - let opts = { - username: username, - password: password, - }; - fetch("/api/protected/behavior", { - method: "post", - body: JSON.stringify(opts), - }).then((response) => { - console.log(response.status); - if (response.status === 401) { - response.json().then((resp) => { - console.log("nicht so wirklich gut"); - // setErrorMessage(resp.message); - }); - } else { - response.json().then((token) => { - console.log("Alles gut :-)"); - }); - } - }); - }; - const study_start = ( <> @@ -189,7 +164,7 @@ export default function Study() { const study_standing = ( <> -
+ Date: Thu, 22 Jul 2021 02:41:24 +0200 Subject: [PATCH 03/11] Started implementing username and password check --- backend/src/app.py | 8 ++++++++ frontend/src/components/pages/Study.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/backend/src/app.py b/backend/src/app.py index 62be6d7..700dd2b 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -119,6 +119,14 @@ def refresh(): return ret, 200 +@app.route('/api/username', methods=['GET']) +@flask_praetorian.auth_required +def get_username(): + user = flask_praetorian.current_user().username + ret = {'username': user} + return user, 200 + + @app.route('/api/protected') @flask_praetorian.auth_required def protected(): diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index c5247c9..2f7b689 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -13,6 +13,7 @@ import BehaviorStudyEnd from "../BehaviorStudyEnd"; export default function Study() { const _logger = useRef(0); + const [serverUsername, setServerUsername] = useState(""); useEffect(() => { _logger.current = new Logger({ @@ -23,6 +24,13 @@ export default function Study() { logToConsole: true, }); _logger.current.init(); + fetch("/api/username", { + method: "get", + }).then((response) => { + response.json().then((resp) => { + setServerUsername(username); + }); + }); }, []); let username = ""; @@ -64,6 +72,10 @@ export default function Study() { return false; }; + const checkValuesStudy = () => { + console.log(serverUsername); + }; + const handleClickAtStepStart = () => { setIsStepStart(false); setIsStepNormal(true); @@ -71,6 +83,7 @@ export default function Study() { }; const handleClickAtStepNormal = () => { + checkValuesStudy(); setIsStepNormal(false); setIsStepPhone(true); }; From 130088756d9921bce04028136d46fdacbdca273b Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 03:11:28 +0200 Subject: [PATCH 04/11] Check if username is the same as in the current session --- backend/src/app.py | 6 +++--- frontend/src/components/pages/Study.js | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/backend/src/app.py b/backend/src/app.py index 700dd2b..8f49861 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -122,9 +122,9 @@ def refresh(): @app.route('/api/username', methods=['GET']) @flask_praetorian.auth_required def get_username(): - user = flask_praetorian.current_user().username - ret = {'username': user} - return user, 200 + username = flask_praetorian.current_user().username + ret = {'username': username} + return ret, 200 @app.route('/api/protected') diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 2f7b689..7e849d1 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -4,12 +4,13 @@ import Footer from "../../Footer"; import InputField from "../InputField"; import SubmitField from "../SubmitField"; import { Logger } from "@behametrics/logger-web"; +import { Button } from "../Button"; import BehaviorStudyInfo from "../BehaviorStudyInfo"; import BehaviorNormal from "../BehaviorNormal"; -import { Button } from "../Button"; import BehaviorPhone from "../BehaviorPhone"; import BehaviorStanding from "../BehaviorStanding"; import BehaviorStudyEnd from "../BehaviorStudyEnd"; +import { authFetch } from "../../auth/AuthProvider"; export default function Study() { const _logger = useRef(0); @@ -24,11 +25,11 @@ export default function Study() { logToConsole: true, }); _logger.current.init(); - fetch("/api/username", { + authFetch("/api/username", { method: "get", }).then((response) => { response.json().then((resp) => { - setServerUsername(username); + setServerUsername(resp.username); }); }); }, []); @@ -72,8 +73,21 @@ export default function Study() { return false; }; - const checkValuesStudy = () => { - console.log(serverUsername); + 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 checkIfValuesAreCorrect = () => { + checkIfUsernameIsCorrect(); }; const handleClickAtStepStart = () => { @@ -83,7 +97,7 @@ export default function Study() { }; const handleClickAtStepNormal = () => { - checkValuesStudy(); + checkIfValuesAreCorrect(); setIsStepNormal(false); setIsStepPhone(true); }; From 7a930c20b625611acd22f79110bb4fbf4ab2ed6c Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 03:11:50 +0200 Subject: [PATCH 05/11] Permissions for requests.sh --- requests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 requests.sh diff --git a/requests.sh b/requests.sh old mode 100644 new mode 100755 From c1fce5bf4a2f782a1bb6f00fcf45196ede9dcf1c Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 03:24:31 +0200 Subject: [PATCH 06/11] Change api for random password --- backend/src/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/app.py b/backend/src/app.py index 8f49861..7f66284 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -141,10 +141,10 @@ def protected(): return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'} -@app.route('/api/protected/rcv_pw', methods=['GET']) +@app.route('/api/rcv_pw', methods=['GET']) def get_password(): pw = get_random_password() - ret = {'password': pw} + ret = {'random_password': pw} return ret, 200 From a6346d749652420d7c9b76b4977830bc0652334d Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 04:44:31 +0200 Subject: [PATCH 07/11] 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 = () => { From 58bd327377e123a8564eafe787405b52c3aacbca Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 05:20:37 +0200 Subject: [PATCH 08/11] Update some change password things.. --- frontend/src/components/BehaviorNormal.js | 7 ++++--- frontend/src/components/GeneratedPassword.js | 5 +++-- frontend/src/components/pages/Study.js | 15 +++++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/BehaviorNormal.js b/frontend/src/components/BehaviorNormal.js index 9f64ef9..c427a02 100644 --- a/frontend/src/components/BehaviorNormal.js +++ b/frontend/src/components/BehaviorNormal.js @@ -1,8 +1,8 @@ import React from "react"; import "../App.css"; -import GeneratedPassword from "./GeneratedPassword" +import GeneratedPassword from "./GeneratedPassword"; -export default function BehaviorNormal() { +export default function BehaviorNormal(props) { return ( <>

@@ -10,7 +10,8 @@ export default function BehaviorNormal() { Passwort eingeben. Verhalten Sie sich einfach so, als ob Sie sich normalerweise anmelden.

- + {console.log("props", props)} + ); } diff --git a/frontend/src/components/GeneratedPassword.js b/frontend/src/components/GeneratedPassword.js index af03882..722fc2a 100644 --- a/frontend/src/components/GeneratedPassword.js +++ b/frontend/src/components/GeneratedPassword.js @@ -1,7 +1,7 @@ import React from "react"; import "../App.css"; -export default function GeneratedPassword() { +export default function GeneratedPassword(props) { const genPassword = "PASSWORT_MANUELL" const handleOnCopyEvent = (e) => { @@ -13,7 +13,8 @@ export default function GeneratedPassword() { <>

Das Passwort für diese Situation lautet:{" "} - {genPassword} + {console.log("component genpw, genpassword", props.genPassword)} + {props.genPassword}

); diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 094479f..e369065 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -83,6 +83,12 @@ export default function Study() { }; const _genPassword = useRef(null); + let genPassword = ""; + + const setGenPassword = (tmp) => { + genPassword = tmp; + console.log("setGenPassword", genPassword, tmp); + }; const receiveRandomPassword = () => { fetch("/api/rcv_pw", { @@ -90,7 +96,8 @@ export default function Study() { }).then((response) => { response.json().then((resp) => { _genPassword.current = resp.random_password; - console.log(_genPassword.current) + console.log(_genPassword.current); + setGenPassword(_genPassword.current); }); }); }; @@ -110,7 +117,7 @@ export default function Study() { if (checkIfPasswordIsCorrect() && checkIfUsernameIsCorrect) { return true; } else { - alert("Passt nicht") + alert("Passt nicht"); return false; } }; @@ -123,7 +130,7 @@ export default function Study() { }; const handleClickAtStepNormal = () => { - if (checkIfValuesAreCorrect()){ + if (checkIfValuesAreCorrect()) { receiveRandomPassword(); setIsStepNormal(false); setIsStepPhone(true); @@ -158,7 +165,7 @@ export default function Study() { const study_normal = ( <> - + Date: Thu, 22 Jul 2021 16:53:08 +0200 Subject: [PATCH 09/11] Receive password and check if it's the same --- frontend/src/components/pages/Study.js | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/pages/Study.js b/frontend/src/components/pages/Study.js index 99fcff9..a0f9df1 100644 --- a/frontend/src/components/pages/Study.js +++ b/frontend/src/components/pages/Study.js @@ -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 = ( From eaa4d8937aadeae1f2a2133eb1150295e7ee6db1 Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 16:53:57 +0200 Subject: [PATCH 10/11] use property to show the value of the actual password --- frontend/src/components/BehaviorPhone.js | 4 ++-- frontend/src/components/BehaviorStanding.js | 4 ++-- frontend/src/components/pages/Manual.js | 25 ++++++++++++++------- frontend/src/components/pages/Study.js | 6 ++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/BehaviorPhone.js b/frontend/src/components/BehaviorPhone.js index 9a6787e..92cc8f0 100644 --- a/frontend/src/components/BehaviorPhone.js +++ b/frontend/src/components/BehaviorPhone.js @@ -2,7 +2,7 @@ import React from "react"; import "../App.css"; import GeneratedPassword from "./GeneratedPassword"; -export default function BehaviorPhone() { +export default function BehaviorPhone(props) { return ( <>

@@ -11,7 +11,7 @@ export default function BehaviorPhone() { Sie sich vor, dass Sie gerade am Telefonieren sind. Verwenden Sie bitte kein Headset oder Ähnliches.

- + ); } diff --git a/frontend/src/components/BehaviorStanding.js b/frontend/src/components/BehaviorStanding.js index 479b59b..e3c1486 100644 --- a/frontend/src/components/BehaviorStanding.js +++ b/frontend/src/components/BehaviorStanding.js @@ -2,13 +2,13 @@ import React from "react"; import "../App.css"; import GeneratedPassword from "./GeneratedPassword" -export default function BehaviorStanding() { +export default function BehaviorStanding(props) { return ( <>

In dieser Situation geht es darum, dass Sie das Passwort im Stehen eingeben. Stehen Sie also vor den Computer und geben Sie den Benutzernamen und das Passwort wie gewohnt ein.

- + ); } diff --git a/frontend/src/components/pages/Manual.js b/frontend/src/components/pages/Manual.js index 3cb29b0..fb9557e 100644 --- a/frontend/src/components/pages/Manual.js +++ b/frontend/src/components/pages/Manual.js @@ -28,21 +28,30 @@ export default function Manual() { zurückzusetzen. Nach der Registrierung landen Sie auf einer Umfrageseite. Füllen Sie die Fragen wahrheitsgemäss aus und klicken Sie danach auf "Umfrage abschicken". Nachdem die Umfrage durchgeführt - wurde, können Sie an der Studie teilnehmen, indem Sie auf den Button "Studie starten" klicken. Folgen Sie danach den Anweisungen gemäss der Studie. + wurde, können Sie an der Studie teilnehmen, indem Sie auf den Button + "Studie starten" klicken. Folgen Sie danach den Anweisungen gemäss der + Studie.

War schon einmal hier

- Wenn Sie schon einmal hier waren, gibt es zwei mögliche Zustände: -

    -
  • Sie sind noch eingeloggt
  • -
  • Sie sind nicht mehr eingeloggt
  • -
+ Wenn Sie schon einmal hier waren, gibt es zwei mögliche Zustände: +
    +
  • Sie sind noch eingeloggt
  • +
  • Sie sind nicht mehr eingeloggt
  • +

- Sofern Sie noch nicht eingeloggt sind, können Sie sich anmelden mit ihrem gewählten Benutzernamen und dem Passwort. Sie landen dann direkt auf der Seite, welche ich für meine Studie benötige. Führen Sie dort die Studie die Studie wie gewohnt durch und beenden Sie diese am Schluss der Studie mit dem Button "Studie beenden". + Sofern Sie noch nicht eingeloggt sind, können Sie sich anmelden mit + ihrem gewählten Benutzernamen und dem Passwort. Sie landen dann direkt + auf der Seite, welche ich für meine Studie benötige. Führen Sie dort + die Studie die Studie wie gewohnt durch und beenden Sie diese am + Schluss der Studie mit dem Button "Studie beenden".

- Wenn Sie bereits eingeloggt sind, dann landen Sie auf der Startseite. Sie finden in der Mitte einen Button mit der Überschrift "Zur Studie". Klicken Sie bitte auf diesen Button und führen Sie dann die Studie durch. + Wenn Sie bereits eingeloggt sind, dann landen Sie auf der Startseite. + Sie finden in der Mitte einen Button mit der Überschrift "Zur Studie". + Klicken Sie bitte auf diesen Button und führen Sie dann die Studie + durch.