refactor a bit

This commit is contained in:
Matt Wright
2012-07-11 15:14:20 -04:00
parent b9a6a9c5a8
commit b3de4a76d5
2 changed files with 21 additions and 25 deletions
+11 -13
View File
@@ -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
+10 -12
View File
@@ -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