Starting to add feedback in the registration (fixes #78)
This commit is contained in:
parent
10766dc601
commit
a032ca946e
2 changed files with 28 additions and 11 deletions
|
@ -144,6 +144,10 @@ 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)
|
||||||
|
|
||||||
|
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(
|
new_user = User(
|
||||||
username=username,
|
username=username,
|
||||||
password=guard.hash_password(password)
|
password=guard.hash_password(password)
|
||||||
|
@ -154,6 +158,12 @@ def register():
|
||||||
new_user.username
|
new_user.username
|
||||||
)}
|
)}
|
||||||
return ret, 200
|
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'])
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue