From 3cbfd949e48798df15685d63a3db55157ff211f8 Mon Sep 17 00:00:00 2001 From: cami Date: Sun, 4 Jul 2021 23:31:18 +0200 Subject: [PATCH] Give feedback when someone wants to register --- backend/src/app.py | 2 +- frontend/src/components/pages/Register.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/src/app.py b/backend/src/app.py index c4b6d57..f5048d0 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -147,7 +147,7 @@ def register(): ) db.session.add(new_user) db.session.commit() - ret = {'message': 'Account erstellt für den Account {}'.format( + ret = {'message': 'Account erstellt für den Account {}. Du kannst dich nun einloggen'.format( new_user.username )} return ret, 200 diff --git a/frontend/src/components/pages/Register.js b/frontend/src/components/pages/Register.js index e8c4195..310601c 100644 --- a/frontend/src/components/pages/Register.js +++ b/frontend/src/components/pages/Register.js @@ -11,6 +11,9 @@ export default function Login() { const [password, setPassword] = useState(""); const [message, setMessage] = useState(""); + const [errorMessage, setErrorMessage] = useState(""); + + const [isStatusOk, setIsStatusOk] = useState(""); const onSubmitClick = (e) => { e.preventDefault(); @@ -22,16 +25,19 @@ export default function Login() { method: "post", body: JSON.stringify(opts), }).then((response) => { - console.log(response); if (response.status === 409) { /* then is needed twice to get rid of the javascript Promise thing */ + setIsStatusOk(false); response.json().then((resp2) => { - setMessage(resp2.message); + setErrorMessage(resp2.message); }); } else if (response.status === 200) { - //TODO redirect to login #77 or #74 + response.json().then((resp) => { + setMessage(resp.message); + }); + setIsStatusOk(true); } }); }; @@ -55,7 +61,7 @@ export default function Login() { onChange={handleUsernameChange} InputName="username" /> -

{message}

+ {!isStatusOk &&

{errorMessage}

} + + {isStatusOk &&

{message}

}