Skip to content Skip to sidebar Skip to footer

Django Django-allauth Save Extra_data From Social Login In Signal

Setup I'm using Django 1.8.15 and django-allauth 0.28.0 Description What I want to do is pretty easy to explain: If a user logs in via social media (facebook, google+ or twitter) i

Solution 1:

got it after some hours of desperation.

I've just used another signal user_signed_up, not the one from the socialaccount

from allauth.account.signals import user_signed_up

@receiver(user_signed_up)
def retrieve_social_data(request, user, **kwargs):
    """Signal, that gets extra data from sociallogin and put it to profile."""
    # get the profile where i want to store the extra_data
    profile = Profile(user=user)
    # in this signal I can retrieve the obj from SocialAccount
    data = SocialAccount.objects.filter(user=user, provider='facebook')
    # check if the user has signed up via social media
    if data:
        picture = data[0].get_avatar_url()
        if picture:
            # custom def to save the pic in the profile
            save_image_from_url(model=profile, url=picture)
        profile.save()

http://django-allauth.readthedocs.io/en/latest/signals.html#allauth-account


Post a Comment for "Django Django-allauth Save Extra_data From Social Login In Signal"