omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

PSA, break pipeline, ask for password and return back problem #982

Closed tyapkov closed 7 years ago

tyapkov commented 8 years ago

I am trying to create a minimal working example in which I am breaking Python Social Auth pipeline, ask for new password from the user and return back.

Here is the custom pipeline function:

@partial
def get_password(strategy, backend, request, user = None, is_new = False, *args, **kwargs):

    if user:
        if is_new:
            if not request.get('password', None):
                return redirect("accounts:get_password")

            user = User.objects.get(email=kwargs['email'])
            user.set_password(request['password'])
            user.save()

    return

Here is the view:

def get_password(request, template_name='accounts/password_change_form.html',extra_context=None):

    if not extra_context: extra_context = dict()

    if request.method == 'POST':
        form = PasswordForm(request.POST)
        if form.is_valid():
            request.session['password'] = form.cleaned_data['password1']

            backend = request.session['partial_pipeline']['backend']
            return redirect('social:complete', backend=backend)
    else:
        form = PasswordForm()
        extra_context["form"] = form

    return ExtraContextTemplateView.as_view(template_name=template_name,
                                          extra_context=extra_context)(request)

Here is line from settings related to 'password' field:

SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['password',]

Everything seems to be according to the examples described in PSA docs. The only one difference - it is not working and password saved in session not returned to the pipeline. Please, help, if you have any ideas how to repair it.

omab commented 7 years ago

Try with strategy.session_get('password') in your pipeline.