Skip to content

Commit

Permalink
Write correct locale to user profile when signing up via social
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgio93p committed Jan 17, 2020
1 parent a7474a3 commit a306b1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cjworkbench/allauth_account_adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from cjworkbench.i18n.templates import context_processor
from cjworkbench.models.userprofile import UserProfile
from django.contrib.sites.shortcuts import get_current_site
from django.conf import settings
from django.template.loader import render_to_string
Expand Down Expand Up @@ -53,3 +55,17 @@ def add_message(
messages.add_message(request, level, message, extra_tags=extra_tags)
except TemplateDoesNotExist:
pass


class SocialAccountAdapter(DefaultSocialAccountAdapter):
def save_user(self, request, sociallogin, form=None):
"""
Saves a newly signed up social login. In case of auto-signup,
the signup form is not available.
"""
u = super().save_user(request, sociallogin, form=None)
# User profile
UserProfile.objects.update_or_create(
user=u, defaults={"locale_id": request.locale_id}
)
return u
1 change: 1 addition & 0 deletions cjworkbench/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@

# For django-allauth
ACCOUNT_ADAPTER = "cjworkbench.allauth_account_adapter.AccountAdapter"
SOCIALACCOUNT_ADAPTER = "cjworkbench.allauth_account_adapter.SocialAccountAdapter"

# EMAIL_BACKEND
#
Expand Down

0 comments on commit a306b1d

Please sign in to comment.