From 130088756d9921bce04028136d46fdacbdca273b Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 03:11:28 +0200 Subject: [PATCH] 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); };