1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-28 23:44:19 +00:00

The hell was I thinking

This commit is contained in:
Lorenzo Balugani 2021-05-12 23:09:29 +02:00
parent 46ed8416d1
commit b0217d6f36

View file

@ -71,11 +71,12 @@ def page_users():
if request.method == "POST": if request.method == "POST":
if not user.isAdmin: if not user.isAdmin:
return json_error("User is not admin. Thou art not authorized."), 403 return json_error("User is not admin. Thou art not authorized."), 403
if not request.json.get("email") or request.json.get("password") or request.json.get("username"): if not request.json.get("email") or not request.json.get("password") or not request.json.get("username"):
return json_error("Missing required fields."), 400 return json_error("Missing required fields."), 400
if User.query.filter_by(email=request.json.get("email")).first(): if User.query.filter_by(email=request.json.get("email")).first():
return json_error("User already exists."), 406 return json_error("User already exists."), 406
new_user = User(email=request.json.get("email"), password=gen_password(request.json.get("password")), new_user = User(email=request.json.get("email"), password=gen_password(request.json.get("password")),
username=request.json.get("username")) username=request.json.get("username"))
ext.session.add(new_user) ext.session.add(new_user)
ext.session.commit()
return json_success(new_user.to_json()), 201 return json_success(new_user.to_json()), 201