Question

In my app I am using standard auth module and social auth plugin. I want to detect if user is registering via oauth or standard method

I have function registered to post_save signal:

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        key, expires = UserProfile.generate_activation_data()
        return UserProfile.objects.create(user=instance, activation_key=key, key_expires=expires)

post_save.connect(create_user_profile, sender=User)

But when user is registered via oauth I would to avoid creating activation data, instead set some field indicated that user is register by oauth.

Could someone give me any advice?

Was it helpful?

Solution

Add a pipeline method that sets a flag in the user instance, something like this:

def created_by_social_auth(user, *args, **kwargs):
    user.by_social_auth = True

Also you could check if the user has any UserSocialAuth instance releated with:

user.social_auth.count()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top