Skip to content

Commit

Permalink
Check and update email addres from github (#8245)
Browse files Browse the repository at this point in the history
  • Loading branch information
amustapha authored Jan 18, 2021
1 parent bd3d86d commit 2437391
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from django.utils.translation import gettext_lazy as _

from app.utils import sync_profile
from git.utils import get_github_primary_email
from cacheops import cached_view
from chartit import PivotChart, PivotDataPool
from dashboard.models import Activity, HackathonEvent, Profile, TokenApproval
Expand Down Expand Up @@ -107,6 +108,16 @@ def settings_helper_get_auth(request, key=None):
is_logged_in = bool(request.user.is_authenticated)
es = EmailSubscriber.objects.none()

# check if user's email has changed
if request.user.is_authenticated:
current_email = get_github_primary_email(request.user.profile.github_access_token)
if current_email != request.user.profile.email:
request.user.profile.email = current_email
request.user.profile.save()
if current_email != request.user.email:
request.user.email = current_email
request.user.save()

# find the user info
if key is None or not EmailSubscriber.objects.filter(priv=key).exists():
email = request.user.email if request.user.is_authenticated else None
Expand All @@ -115,6 +126,9 @@ def settings_helper_get_auth(request, key=None):
if hasattr(request.user, 'profile'):
if request.user.profile.email_subscriptions.exists():
es = request.user.profile.email_subscriptions.first()
if es.email != request.user.profile.email:
es.email = request.user.profile.email
es.save()
if not es or es and not es.priv:
es = get_or_save_email_subscriber(
request.user.email, 'settings', profile=request.user.profile)
Expand Down

0 comments on commit 2437391

Please sign in to comment.