Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-social-auth partial pipeline can not resume

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.

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

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

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))
like image 250
user3179510 Avatar asked Jan 09 '14 22:01

user3179510


1 Answers

Ok. I found the problem and the solution.

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:

pipeline:

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
like image 89
user3179510 Avatar answered Oct 11 '22 12:10

user3179510