Add Feedback at the registration process (fix #78) #79
2 changed files with 28 additions and 11 deletions
|
@ -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'])
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue