Add a form for changing the password and prompt the user to do so when there is no password on the account.
This commit is contained in:
parent
e016d5822f
commit
16ee147eae
7 changed files with 98 additions and 10 deletions
|
@ -51,8 +51,35 @@ def get_logged_in_user():
|
|||
'username': user.username,
|
||||
'email': user.email,
|
||||
'gravatar': compute_hash(user.email),
|
||||
'askForPassword': user.password_hash is None,
|
||||
})
|
||||
|
||||
@app.route('/api/user/', methods=['PUT'])
|
||||
@api_login_required
|
||||
def change_user_details():
|
||||
user = current_user.db_user
|
||||
|
||||
user_data = request.get_json();
|
||||
|
||||
try:
|
||||
if user_data['password']:
|
||||
logger.debug('Changing password for user: %s', user.username)
|
||||
model.change_password(user, user_data['password'])
|
||||
except model.InvalidPasswordException, ex:
|
||||
error_resp = jsonify({
|
||||
'message': ex.message,
|
||||
})
|
||||
error_resp.status_code = 400
|
||||
return error_resp
|
||||
|
||||
return jsonify({
|
||||
'verified': user.verified,
|
||||
'anonymous': False,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'gravatar': compute_hash(user.email),
|
||||
'askForPassword': user.password_hash is None,
|
||||
})
|
||||
|
||||
@app.route('/api/user/', methods=['POST'])
|
||||
def create_user_api():
|
||||
|
@ -60,7 +87,7 @@ def create_user_api():
|
|||
existing_user = model.get_user(user_data['username'])
|
||||
if existing_user:
|
||||
error_resp = jsonify({
|
||||
'message': 'The username already exists'
|
||||
'message': 'The username already exists'
|
||||
})
|
||||
error_resp.status_code = 400
|
||||
return error_resp
|
||||
|
|
Reference in a new issue