python-social-auth部分管道无法恢复 [英] python-social-auth partial pipeline can not resume

查看:50
本文介绍了python-social-auth部分管道无法恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python-social-auth的部分管道来收集新用户的密码.出于某些未知原因,我无法恢复管道,提交表单后,该页面将呈现回密码收集页面.

I am trying to collect the password for the new user with partial pipeline of python-social-auth. For some unknown reason, I am not able to resume the pipeline, the page render back to the password collection page after I submit the form.

连接的是,即使我键入了http .../complete/backend-name,该页面也将重定向回密码收集页面.看起来渲染进入一个无休止的循环,密码收集页面首先指向完整页面,完整页面直接回到密码收集页面.我检查了REDIRECT_FIELD_NAME的值,它是"next".

What's wired is that even I typed the http.../complete/backend-name, the page will redirect back to the password collection page. It looks like the rendering goes into an endless loop, the password collection page first point to the complete page, the complete page direct back to the password collection page. I checked the value for REDIRECT_FIELD_NAME, it is "next".

我不确定我的代码有什么问题,任何提示/建议都将不胜感激.

I am not sure what's wrong with my code, any tips/suggestions are greatly appreciated.

settings.py

settings.py

SOCIAL_AUTH_PIPELINE = (
    ...
    'accounts.pipeline.get_password',
    ...
)

pipeline.py

pipeline.py

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new:
        return redirect('accounts_signup_social')
    else:
        return

views.py

def get_password(request):
    if request.method == 'POST':
        request.session['password'] = request.POST.get('password')
        backend = request.session['partial_pipeline']['backend']
        return redirect('social:complete', backend=backend)
    return render_to_response('accounts/social_signup.html',{"form":SocialSignUpForm}, RequestContext(request))

推荐答案

好.我找到了问题和解决方法.

Ok. I found the problem and the solution.

正如文档所述,管道将以与削减进程相同的功能恢复."在 http://python-social-auth.readthedocs.org/en/latest/pipeline.html.这意味着它将始终呈现回相同的功能.

As the documentation said, "The pipeline will resume in the same function that cut the process." at http://python-social-auth.readthedocs.org/en/latest/pipeline.html. Which means it will always render back to the same function.

解决方案是在管道中添加会话检查密码.如果密码已存档,请返回下一个管道:

The solution is to add the session check for the password in the pipeline. Return back to the next pipeline if the password is archived:

管道:

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new:
        if 'password' in kwargs['request'].session:
            return {'password': kwargs['request'].session['psssword']}
        else:
            return redirect('accounts_signup_social')
    else:
        return

这篇关于python-social-auth部分管道无法恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆