Starting to add feedback in the registration (fixes #78)

This commit is contained in:
cami 2021-06-28 03:46:27 +02:00
parent 10766dc601
commit a032ca946e
2 changed files with 28 additions and 11 deletions

View file

@ -144,16 +144,26 @@ def register():
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)
new_user = User(
username=username, get_list_by_username = User.query.filter_by(username=username).first()
password=guard.hash_password(password) print(get_list_by_username)
) if get_list_by_username is None:
db.session.add(new_user) new_user = User(
db.session.commit() username=username,
ret = {'message': 'Account erstellt für den Account {}'.format( password=guard.hash_password(password)
new_user.username )
)} db.session.add(new_user)
return ret, 200 db.session.commit()
ret = {'message': 'Account erstellt für den Account {}'.format(
new_user.username
)}
return ret, 200
else:
ret = {'message': 'Benutzername {} existiert bereits. Bitte wähle einen anderen '.format(
username
)}
return ret, 409
@app.route('/umfrage', methods=['POST']) @app.route('/umfrage', methods=['POST'])

View file

@ -9,16 +9,23 @@ export default function Login() {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [message, setMessage] = useState("");
const onSubmitClick = (e) => { const onSubmitClick = (e) => {
e.preventDefault(); e.preventDefault();
let opts = { let opts = {
username: username, username: username,
password: password, password: password,
}; };
console.log(opts);
fetch("/api/register", { fetch("/api/register", {
method: "post", method: "post",
body: JSON.stringify(opts), body: JSON.stringify(opts),
}).then((response) => {
if (response.status === 409) {
setMessage(response.message)
console.log(message)
console.log(response)
}
}); });
}; };