Skip to content

Instantly share code, notes, and snippets.

@goltsevnet
Created February 18, 2019 12:07
Show Gist options
  • Select an option

  • Save goltsevnet/a73bbe0fae332add07ba2659feb4ab6e to your computer and use it in GitHub Desktop.

Select an option

Save goltsevnet/a73bbe0fae332add07ba2659feb4ab6e to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import User
from allauth.account.models import EmailAccount
from allauth.exceptions import ImmediateHttpResponse
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
class MyAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
# This isn't tested, but should work
try:
user = User.objects.get(email=sociallogin.email)
sociallogin.connect(request, user)
# Create a response object
raise ImmediateHttpResponse(response)
except User.DoesNotExist:
pass
SOCIALACCOUNT_ADAPTER = 'myapp.my_adapter.MyAdapter`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment