简体   繁体   English

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

[英]Django: How to identifying through which link user done social authentication?

I am new to Django development environment. 我是Django开发环境的新手。 Please help me in how to implement scenario like following in Django application. 请帮助我如何在Django应用程序中实现以下方案。

In my web page, there are links available for do social signup/login using python-social-auth module (for facebook and google). 在我的网页上,有可用python-social-auth模块(适用于facebook和google)进行社交注册/登录的链接。 There is two type of users are there in my system, TypeA and TypeB. 我的系统中有两种类型的用户:TypeA和TypeB。

In web page there will be different links for each of the type ( like TypeA-Facebook-Login, TypeB-Facebook-Login ). 在网页中,每种类型都会有不同的链接( 例如TypeA-Facebook-Login,TypeB-Facebook-Login )。

When ever a user is created through python-social-auth service, a User entry is added up, using django.dispatch.receiver I want to make entry to table TypeAUser or TypeBUser . 每当通过python-social-auth服务创建User时,都会使用django.dispatch.receiverUser条目添加到表TypeAUserTypeBUser

*So, how can I understand through which link user is signed-up? *那么,我如何了解通过哪个链接用户注册?

I have tried like following with a extra parameter in the social-auth links, but how can I access that information later on ? 我尝试过在社交身份验证链接中添加一个额外的参数,但是以后如何访问该信息?

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

Below is how I written @reciver function. 以下是我编写@reciver函数的方式。

@receiver(post_save, sender=User,dispatch_uid="add_user_profile")
def add_user_profile(sender,instance, **kwargs):

Many many thanks, for the suggestions and inputs. 非常感谢您的建议和意见。

Seems to be I myself figured out to implement this by SOCIAL_AUTH_PIPELINE concept based on the following documentation reference . 我本人似乎是根据下面的文档参考,通过SOCIAL_AUTH_PIPELINE概念实现了这一SOCIAL_AUTH_PIPELINE

following is the modifications I have done: Added SOCIAL_AUTH_PIPELINE into setting.py with custom a pipeline 以下是我所做的修改:使用自定义管道将SOCIAL_AUTH_PIPELINE添加到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'
)

Also added FIELDS_STORED_IN_SESSION in settings.py , as follows 还添加FIELDS_STORED_IN_SESSIONsettings.py ,如下

FIELDS_STORED_IN_SESSION = ['profile_type']

Then in user_profile.pipeline.py , defined function create_user_profile as follows: 然后在user_profile.pipeline.py ,定义函数create_user_profile如下:

def create_user_profile(strategy, details, user=None, is_new=False, *args, **kwargs):
    print(strategy.session_get('profile_type'))

Now from strategy object I can access the custom value to create different type of user profile. 现在,从策略对象中,我可以访问自定义值来创建不同类型的用户配置文件。 Link of reference 参考链接

On the main link in which user clicks, added an extra argument at the end of url as follows: 在用户单击的主链接上,在url的末尾添加一个额外的参数,如下所示:

http://domain.name.com/signupurl?profile_type=type1
http://domain.name.com/signupurl?profile_type=type2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM