如何在使用多授权提供程序时获取信号发送方类型?

时间:2022-09-11 18:26:32

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

在我的应用程序中,我使用标准的auth模块和社交身份验证插件。我想检测用户是否通过oauth或标准方法注册

I have function registered to post_save signal:

我有函数注册到post_save信号:

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.

但是当用户通过oauth注册时我会避免创建激活数据,而是设置一些字段表示用户是由oauth注册的。

Could someone give me any advice?

有人可以给我任何建议吗?

1 个解决方案

#1


1  

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:

您还可以检查用户是否有任何与之相关的UserSocialAuth实例:

user.social_auth.count()

#1


1  

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:

您还可以检查用户是否有任何与之相关的UserSocialAuth实例:

user.social_auth.count()