Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:如何识别用户通过哪个链接进行社会认证?_Python_Django_Facebook_Authentication_Python Social Auth - Fatal编程技术网

Python Django:如何识别用户通过哪个链接进行社会认证?

Python Django:如何识别用户通过哪个链接进行社会认证?,python,django,facebook,authentication,python-social-auth,Python,Django,Facebook,Authentication,Python Social Auth,我是Django开发环境的新手。请帮助我如何在Django应用程序中实现如下场景 在我的网页中,有一些链接可用于使用python social auth模块(用于facebook和google)进行社交注册/登录。在我的系统中有两种类型的用户,TypeA和TypeB 在网页中,每种类型都会有不同的链接(比如A型Facebook登录,B型Facebook登录) 当通过python social auth服务创建用户时,将使用django.dispatch.receiver向表TypeAUser或T

我是Django开发环境的新手。请帮助我如何在Django应用程序中实现如下场景

在我的网页中,有一些链接可用于使用python social auth模块(用于facebook和google)进行社交注册/登录。在我的系统中有两种类型的用户,TypeA和TypeB

在网页中,每种类型都会有不同的链接(比如A型Facebook登录,B型Facebook登录)

当通过python social auth服务创建用户时,将使用
django.dispatch.receiver
向表
TypeAUser
TypeBUser
添加一个
user
条目

*那么,我如何理解用户是通过哪个链接注册的呢

我尝试过在social auth链接中添加一个额外的参数,但以后如何访问该信息

<a href="{% url 'social:begin' 'facebook' %}?next={{request.path}}&profile_type=typea">
Login with faceboook</a>

非常感谢您的建议和意见。

似乎是我自己根据以下文档通过
SOCIAL\u AUTH\u PIPELINE
概念实现的

以下是我所做的修改: 使用自定义管道将
SOCIAL\u AUTH\u管道
添加到
setting.py

# social authentication pipeline
SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
# custom pipeline
    'user_profile.pipeline.create_user_profile'
)
还在
settings.py
中添加了存储在会话中的
字段,如下所示

FIELDS_STORED_IN_SESSION = ['profile_type']
然后在
user\u profile.pipeline.py
中,定义函数
create\u user\u profile
,如下所示:

def create_user_profile(strategy, details, user=None, is_new=False, *args, **kwargs):
    print(strategy.session_get('profile_type'))
http://domain.name.com/signupurl?profile_type=type1
http://domain.name.com/signupurl?profile_type=type2
现在,我可以从strategy object访问自定义值来创建不同类型的用户配置文件。

在用户单击的主链接上,在url末尾添加了一个额外参数,如下所示:

def create_user_profile(strategy, details, user=None, is_new=False, *args, **kwargs):
    print(strategy.session_get('profile_type'))
http://domain.name.com/signupurl?profile_type=type1
http://domain.name.com/signupurl?profile_type=type2

您是如何使用两个版本的用户模型设置contrib.auth的?@khajvah:我没有修改contrib.auth模块,只是添加了新的模型,如
TypeAUser
TypeBUser
,它们将
models.OneToOneField('auth.user',primary_key=True)
作为一个用户字段。我认为这不是一个好的解决方案。我建议您创建一个新表
UserTypes
,然后从
auth.User
向该新表添加一个新外键。或者更简单的解决方案是使用内置的
UserGroups
。也就是说,有两个组“A”和“B”,然后给每个用户提供组A或组BI。我不确定python social auth的工作原理。我猜,它会自动创建/验证用户。如果是这样的话,你需要更深入地了解插件本身。我只是指出了一个更大的问题。