Merge pull request 'Give feedback when someone wants to register' (#97) from register/errorText into main

Reviewed-on: #97
This commit is contained in:
cami 2021-07-04 21:31:58 +00:00
commit d073c8ea2e
2 changed files with 13 additions and 5 deletions

View file

@ -147,7 +147,7 @@ def register():
) )
db.session.add(new_user) db.session.add(new_user)
db.session.commit() 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 new_user.username
)} )}
return ret, 200 return ret, 200

View file

@ -11,6 +11,9 @@ export default function Login() {
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [errorMessage, setErrorMessage] = useState("");
const [isStatusOk, setIsStatusOk] = useState("");
const onSubmitClick = (e) => { const onSubmitClick = (e) => {
e.preventDefault(); e.preventDefault();
@ -22,16 +25,19 @@ export default function Login() {
method: "post", method: "post",
body: JSON.stringify(opts), body: JSON.stringify(opts),
}).then((response) => { }).then((response) => {
console.log(response);
if (response.status === 409) { if (response.status === 409) {
/* /*
then is needed twice to get rid of the javascript Promise thing then is needed twice to get rid of the javascript Promise thing
*/ */
setIsStatusOk(false);
response.json().then((resp2) => { response.json().then((resp2) => {
setMessage(resp2.message); setErrorMessage(resp2.message);
}); });
} else if (response.status === 200) { } 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} onChange={handleUsernameChange}
InputName="username" InputName="username"
/> />
<p className="errorMessage">{message}</p> {!isStatusOk && <p className="errorMessage">{errorMessage}</p>}
<InputField <InputField
LabelName="Passwort" LabelName="Passwort"
InputType="password" InputType="password"
@ -65,6 +71,8 @@ export default function Login() {
<br /> <br />
<SubmitField onClick={onSubmitClick} LabelName="Registrieren" /> <SubmitField onClick={onSubmitClick} LabelName="Registrieren" />
</form> </form>
{isStatusOk && <p>{message}</p>}
</div> </div>
<Footer /> <Footer />
</> </>