Add ability to view and change an account’s email address
This commit is contained in:
parent
d5bbea9fb2
commit
a363ada41c
8 changed files with 123 additions and 13 deletions
|
@ -337,8 +337,12 @@ def list_federated_logins(user):
|
|||
FederatedLogin.user == user)
|
||||
|
||||
|
||||
def create_confirm_email_code(user):
|
||||
code = EmailConfirmation.create(user=user, email_confirm=True)
|
||||
def create_confirm_email_code(user, new_email=None):
|
||||
if new_email:
|
||||
if not validate_email(new_email):
|
||||
raise InvalidEmailAddressException('Invalid email address: %s' % new_email)
|
||||
|
||||
code = EmailConfirmation.create(user=user, email_confirm=True, new_email=new_email)
|
||||
return code
|
||||
|
||||
|
||||
|
@ -347,15 +351,20 @@ def confirm_user_email(code):
|
|||
code = EmailConfirmation.get(EmailConfirmation.code == code,
|
||||
EmailConfirmation.email_confirm == True)
|
||||
except EmailConfirmation.DoesNotExist:
|
||||
raise DataModelException('Invalid email confirmation code.')
|
||||
raise DataModelException('Invalid email confirmation code.')
|
||||
|
||||
user = code.user
|
||||
user.verified = True
|
||||
|
||||
new_email = code.new_email
|
||||
if new_email:
|
||||
user.email = new_email
|
||||
|
||||
user.save()
|
||||
|
||||
code.delete_instance()
|
||||
|
||||
return user
|
||||
return {'user': user, 'new_email': new_email}
|
||||
|
||||
|
||||
def create_reset_password_email_code(email):
|
||||
|
@ -384,6 +393,13 @@ def validate_reset_code(code):
|
|||
return user
|
||||
|
||||
|
||||
def find_user_by_email(email):
|
||||
try:
|
||||
return User.get(User.email == email)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
def get_user(username):
|
||||
try:
|
||||
return User.get(User.username == username, User.organization == False)
|
||||
|
|
Reference in a new issue