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)
username = req.get('username', None)
password = req.get('password', None)
new_user = User(
username=username,
password=guard.hash_password(password)
)
db.session.add(new_user)
db.session.commit()
ret = {'message': 'Account erstellt für den Account {}'.format(
new_user.username
)}
return ret, 200
get_list_by_username = User.query.filter_by(username=username).first()
print(get_list_by_username)
if get_list_by_username is None:
new_user = User(
username=username,
password=guard.hash_password(password)
)
db.session.add(new_user)
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'])

View file

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