我想为2种不同的用户类型创建2种不同的注册机制,即消费者用户和供应商用户。用python-social-auth做最简单的方法是什么?
为了集中讨论,我们假设有两个注册页面:example.com/consumer-signup
和example.com/vendor-signup
。这个问题归结为我如何将每个页面的值传递给社交身份验证管道或facebook等身份验证器,这样我就可以在身份验证完成后检索相同的值。
由于
答案 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':
...