0

My Django project lets users log in with a Google or Facebook profile, using python-social-auth's django integration.

Once they've logged in, is there a way to get a link to their profile on Google or Facebook? I'm trying to do something like this:

from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.core.mail import mail_admins

@receiver(post_save, sender=User)
def alert_new_user(sender, **kwargs):
    instance = kwargs['instance']
    social = instance.social_auth.last() # Assuming .last() gives me the one just added
    if social is not None:
        mail_admins('New user resistration',
            'A new user registered with name {}'.format(instance.get_full_name()),
            '<html><head/><body>A new user, <a href="{}">{}</a>, registered.</body></html>'.format(
                ???What goes here???, instance.get_full_name()
            )
        )
Tom
  • 7,269
  • 1
  • 42
  • 69

1 Answers1

0

You can get a link to their Facebook profile before they are logged in.

In the pipeline, there is a function called social_details which get information about the user from specified social network.

If we take a look at that method, it is pretty simple:

def social_details(backend, details, response, *args, **kwargs):
    return {'details': dict(backend.get_user_details(response),
                            **details)}

and if you print the response:

def social_details(backend, details, response, *args, **kwargs):
    print(response)
    return {'details': dict(backend.get_user_details(response),
                            **details)}

you will see that there is a parameter link, provided login is through Facbook. Now you can get that link and save/use it however you want.

Jahongir Rahmonov
  • 13,083
  • 10
  • 47
  • 91