Search code examples
djangopython-social-auth

Python social auth partial pipeline resume after form submit button


I have a partial func pipeline that waits for a form to click the submit button. When the button is clicked, the pipeline should move on. I was thinking on this approach, but how can I get the request object in pipeline?

<form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
<input type="submit" value="Submit", name="SumbitSocialData">


@partial
def partial_pipeline(backend, user, response, is_new=None, *args, **kwargs):
    ...
    request = ?
    if 'SumbitSocialData' in request.POST:
        # move on

How can i acces the request object in pipeline?

Does someone has a better ideea about how to implement this?


Solution

  • I solved it, by adding a submit_social_data value in the session, inside the view code:

    def form_valid(self, form):
        ...
        self.request.session['submit_social_data'] = True
        return redirect(self.get_success_url())
    

    Than, in the pipeline I check if is a new social account and if it clicked the button:

    @partial
    def twitter_email(backend, user, response, is_new=None,  *args, **kwargs):
         ...
         submit_social_data = backend.strategy.session.get('submit_social_data', None)
         if is_new and not submit_social_data:
                    return redirect('redirect_url')