Skip to content

Commit

Permalink
fix(email): make sure to update email in db even if user has logged i…
Browse files Browse the repository at this point in the history
…n before
  • Loading branch information
Avantol13-machine-user committed Jun 11, 2021
1 parent 1f30488 commit 90ee044
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions fence/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def set_flask_session_values(user):

user = query_for_user(session=current_session, username=username)
if user:
_update_users_email(user, email)

# This expression is relevant to those users who already have user and
# idp info persisted to the database. We return early to avoid
# unnecessarily re-saving that user and idp info.
Expand All @@ -112,11 +114,7 @@ def set_flask_session_values(user):
if not idp:
idp = IdentityProvider(name=provider)

if email and user.email != email:
logger.info(
f"Updating username {user.username}'s email from {user.email} to {email}"
)
user.email = email
_update_users_email(user, email)

user.identity_provider = idp
current_session.add(user)
Expand Down Expand Up @@ -261,3 +259,16 @@ def wrapper(*args, **kwargs):
def admin_login_required(function):
"""Compose the login required and admin required decorators."""
return login_required({"admin"})(admin_required(function))


def _update_users_email(user, email):
"""
Update email if provided and doesn't match db entry.
NOTE: This does NOT commit to the db, do so outside this function
"""
if email and user.email != email:
logger.info(
f"Updating username {user.username}'s email from {user.email} to {email}"
)
user.email = email

0 comments on commit 90ee044

Please sign in to comment.