【问题标题】:SOCIAL_AUTH_FIELDS_STORED_IN_SESSION in python-social-auth is always None in my custom pipelinepython-social-auth 中的 SOCIAL_AUTH_FIELDS_STORED_IN_SESSION 在我的自定义管道中始终为 None
【发布时间】:2016-11-05 00:22:08
【问题描述】:

我正在尝试从我的模板中获取会话社交变量。 我有 2 个单独的按钮用于注册和登录,使用密钥 login_type:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}?login_type=1"><img src='img.png'>  </a>

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}?login_type=2"><img src='img2.png'></a>

在我的设置中:

SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['login_type']

我也试过:

FIELDS_STORED_IN_SESSION = ['login_type']

我的自定义管道:

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',
'FBAuth.facebook.check_if_exists',     
'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',
)

facebook.py:

from django.conf import settings
from django.shortcuts import  redirect, HttpResponse

def check_if_exists(strategy,  request, *args, **kwargs):
    login_type = strategy.request.GET.get('login_type')
    #login_type = strategy.session_get('key') (I tried all cases)
    #login_type = request['login_type']
    #login_type = strategy.request['login_type']
    logger.debug("is_new parameter is %s", kwargs['is_new'])
    logger.debug("login_type is %s", login_type)
    if kwargs['is_new']:
        if login_type == 1:  
            return redirect('/', message ='Specified social account is not yet associate with any existent user, try to Sign up first')
    else: 
        if login_type == 2: 
            return redirect('/', message = 'User for this account is already exist, try to login')
    return None

但是,无论如何,在我的日志中,我总是看到“login_type is None”

怎么了?

【问题讨论】:

    标签: django python-social-auth


    【解决方案1】:

    您的 GET 参数似乎是错误的。你应该改变

    <code><pre>?next={{ request.path }}?login_type=1</pre></code>
    

    <code><pre>?next={{ request.path }}&login_type=1</pre></code>
    

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 2015-02-24
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多