如何使用python-social-auth为多种类型的用户实现注册?

时间:2013-11-20 07:35:18

标签: django django-socialauth

我想为2种不同的用户类型创建2种不同的注册机制,即消费者用户和供应商用户。用python-social-auth做最简单的方法是什么?

为了集中讨论,我们假设有两个注册页面:example.com/consumer-signupexample.com/vendor-signup。这个问题归结为我如何将每个页面的值传递给社交身份验证管道或facebook等身份验证器,这样我就可以在身份验证完成后检索相同的值。

由于

1 个答案:

答案 0 :(得分:3)

您可能希望使用SOCIAL_AUTH_FIELDS_STORED_IN_SESSION配置可以传递到socialauth_begin端点的查询参数。然后,您可以在SOCIAL_AUTH_PIPELINE中检索此值,并访问request.session以获取此值。

类似的东西:

您的设置

SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ('user_type', )

您的登录模板

a href="{% url socialauth_begin '[backend]' %}?user_type=vendor">Sign-in as Vendor</a>

您的管道阶段

def set_user_type(strategy, details, response, user=None, is_new=False, *args, **kwargs):
    user_type = strategy.session.get('user_type')
    if user_type == 'vendor':
        ...