Check in the frontend if the username and password in the survey are correct (fix #179) #185
2 changed files with 23 additions and 9 deletions
|
@ -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')
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue