Added login feedback in the backend

This commit is contained in:
cami 2021-07-04 23:35:20 +02:00
parent d073c8ea2e
commit 160e4d936e
2 changed files with 8 additions and 4 deletions

View file

@ -98,9 +98,13 @@ def login():
req = flask.request.get_json(force=True) req = flask.request.get_json(force=True)
username = req.get('username', None) username = req.get('username', None)
password = req.get('password', None) password = req.get('password', None)
user = guard.authenticate(username, password) try:
ret = {'access_token': guard.encode_jwt_token(user)} user = guard.authenticate(username, password)
return ret, 200 ret = {'access_token': guard.encode_jwt_token(user)}
return ret, 200
except flask_praetorian.exceptions.AuthenticationError:
ret = {'message': "Benutzername und Passwort stimmen nicht überein"}
return ret, 401
@app.route('/api/refresh', methods=['POST']) @app.route('/api/refresh', methods=['POST'])

View file

@ -17,7 +17,6 @@ export default function Login() {
username: username, username: username,
password: password, password: password,
}; };
console.log(opts);
fetch("/api/login", { fetch("/api/login", {
method: "post", method: "post",
body: JSON.stringify(opts), body: JSON.stringify(opts),
@ -27,6 +26,7 @@ export default function Login() {
if (token.access_token) { if (token.access_token) {
login(token); login(token);
} else { } else {
// TODO: add text if the login is not correct
console.log("Please type in the correct username / password"); console.log("Please type in the correct username / password");
} }
}); });