text: from allauth.account.models import EmailAddress
  from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
  from allauth.account.adapter import get_adapter as get_account_adapter
  from allauth.account.utils import user_email, user_field, user_username
  
  class SocialAccountAdapter(DefaultSocialAccountAdapter):
      def pre_social_login(self, request, sociallogin):
          """
          Invoked just after a user successfully authenticates via a
          social provider, but before the login is actually processed
          (and before the pre_social_login signal is emitted).
  
          We're trying to solve different use cases:
          - social account already exists, just go on
          - social account has no email or email is unknown, just go on
          - social account's email exists, link social account to existing user
          """
  
          # Ignore existing social accounts, just do this stuff for new ones
          if sociallogin.is_existing:
              return
  
          # some social logins don't have an email address, e.g. facebook accounts
          # with mobile numbers only, but allauth takes care of this case so just
          # ignore it
          if 'email' not in sociallogin.account.extra_data:
              return
  
          # check if given email address already exists.
          # Note: __iexact is used to ignore cases
          try:
              email = sociallogin.account.extra_data['email'].lower()
              email_address = EmailAddress.objects.get(email__iexact=email)
  
          # if it does not, let allauth take care of this new social account
          except EmailAddress.DoesNotExist:
              return
  
          # if it does, connect this new social login to the existing user
          user = email_address.user
          sociallogin.connect(request, user)
  
      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 = sociallogin.user
          u.set_unusable_password()
          if form:
              get_account_adapter().save_user(request, u, form)
          else:
              get_account_adapter().populate_username(request, u)
          u.username = u.email
          sociallogin.save(request)
  
          try:
              if sociallogin.account.provider == 'facebook':
                  sociallogin.user.profile.picture  = "https://graph.facebook.com/"+sociallogin.account.extra_data['id']+"/picture?type=large"
              if sociallogin.account.provider == 'google':
                  sociallogin.user.profile.picture  = sociallogin.account.extra_data['picture']
              sociallogin.user.profile.save()
          except:
              pass
          return u