mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-04 17:20:07 +08:00
refactor a bit
This commit is contained in:
@@ -96,28 +96,26 @@ def confirm_by_token(token):
|
||||
if md5(user.email) != data[1]:
|
||||
raise UserNotFoundError()
|
||||
|
||||
if user.confirmed_at:
|
||||
raise ConfirmationError('Account has already been confirmed')
|
||||
|
||||
user.confirmed_at = datetime.utcnow()
|
||||
_datastore._save_model(user)
|
||||
|
||||
user_confirmed.send(user, app=app._get_current_object())
|
||||
|
||||
return user
|
||||
|
||||
except UserNotFoundError:
|
||||
raise ConfirmationError('Invalid confirmation token')
|
||||
|
||||
except SignatureExpired:
|
||||
sig_okay, data = serializer.loads_unsafe(token)
|
||||
user = _datastore.find_user(id=data[0])
|
||||
raise TokenExpiredError(message='Confirmation token is expired',
|
||||
user=user)
|
||||
raise TokenExpiredError(user=_datastore.find_user(id=data[0]))
|
||||
|
||||
except BadSignature:
|
||||
raise ConfirmationError('Invalid confirmation token')
|
||||
|
||||
if user.confirmed_at:
|
||||
raise ConfirmationError('Account has already been confirmed')
|
||||
|
||||
user.confirmed_at = datetime.utcnow()
|
||||
_datastore._save_model(user)
|
||||
|
||||
user_confirmed.send(user, app=app._get_current_object())
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def reset_confirmation_token(user):
|
||||
"""Resets the specified user's confirmation token and sends the user
|
||||
|
||||
@@ -86,27 +86,25 @@ def reset_by_token(token, password):
|
||||
if md5(user.password) != data[1]:
|
||||
raise UserNotFoundError()
|
||||
|
||||
user.password = _security.pwd_context.encrypt(password)
|
||||
_datastore._save_model(user)
|
||||
|
||||
send_password_reset_notice(user)
|
||||
|
||||
password_reset.send(user, app=app._get_current_object())
|
||||
|
||||
return user
|
||||
|
||||
except UserNotFoundError:
|
||||
raise ResetPasswordError('Invalid reset password token')
|
||||
|
||||
except SignatureExpired:
|
||||
sig_okay, data = serializer.loads_unsafe(token)
|
||||
user = _datastore.find_user(id=data[0])
|
||||
raise TokenExpiredError('Reset password token is expired', user)
|
||||
raise TokenExpiredError(user=_datastore.find_user(id=data[0]))
|
||||
|
||||
except BadSignature:
|
||||
raise ResetPasswordError('Invalid reset password token')
|
||||
|
||||
user.password = _security.pwd_context.encrypt(password)
|
||||
|
||||
_datastore._save_model(user)
|
||||
|
||||
send_password_reset_notice(user)
|
||||
|
||||
password_reset.send(user, app=app._get_current_object())
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def reset_password_reset_token(user):
|
||||
"""Resets the specified user's reset password token and sends the user
|
||||
|
||||
Reference in New Issue
Block a user