Skip to content
Snippets Groups Projects
Commit 3b478307 authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

changes is updating user

parent 8784b84a
No related branches found
No related tags found
1 merge request!23Resolve "debug and cleanup code"
......@@ -50,24 +50,17 @@ class UserEndpoint(Resource):
def put():
data = request.form
user_id = get_jwt_identity()
if 'name' in data and 'email' in data and 'password' in data:
user = db.session.query(User).filter_by(email=data['email']).first()
if user and bcrypt.check_password_hash(user.pwd, data['password']) and user_id == user.id:
user = db.session.query(User).filter_by(id=user_id).first()
if user is not None:
if 'newName' in data:
if data['newName'] != user.name:
user.name = data['name']
if 'newEmail' in data:
if data['email'] != user.email:
user.email = data['email']
if 'newPassword' in data and 'confirmNewPassword' in data:
if data['newPassword'] == data['confirmNewPassword']:
user.pwd = bcrypt.generate_password_hash(data['newPassword'])
if re.search(EMAIL_REGEX, data['newEmail'].lower()):
user.email = data['newEmail']
db.session.commit()
return jsonify({"message": "user was updated"})
else:
return jsonify({"message": "email og password wrong"})
else:
return jsonify({"message": "wrong data"})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment