Created
April 30, 2017 18:51
-
-
Save BryanTabarez/db163017b58cd4c1fdba0ea5395114ba to your computer and use it in GitHub Desktop.
django-allauth login social account with a local account email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from allauth.account.utils import perform_login | |
from allauth.exceptions import ImmediateHttpResponse | |
from allauth.socialaccount.signals import pre_social_login | |
from django.conf import settings | |
@receiver(pre_social_login) | |
def link_to_local_user(sender, request, sociallogin, **kwargs): | |
email_address = sociallogin.account.extra_data['email'] | |
users = User.objects.filter(email=email_address) | |
if users: | |
user = users[0] | |
if user.is_active: | |
perform_login(request, user, email_verification=False) | |
raise ImmediateHttpResponse( | |
redirect(settings.LOGIN_REDIRECT_URL.format(id=request.user.id))) | |
else: | |
raise ImmediateHttpResponse(redirect('cuenta-inactiva')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment