Python-social-auth partial pipeline parameters form data per session
I am using python-social-auth to login and create a user profile. Unlike the example here , which creates a profile at the end of the pipeline, my application should not allow the creation of a user without a profile. I followed the Django example provided in the github source, so I have a partial pipeline that requires a profile and renders a Django form after successful authentication.
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',
'social.pipeline.user.get_username',
'accounts.pipeline.require_profile',
'accounts.pipeline.create_user_profile',
'social.pipeline.social_auth.associate_user',
'social.pipeline.debug.debug',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
#'social.pipeline.debug.debug'
)
The partial pipeline redirects to a view that displays the login and profile form. Here is the code in the view that validates the form and ends the pipeline.
if profile_form.is_valid():
request.session['form_data'] = profile_form.cleaned_data
...
return redirect('social:complete', backend=backend)
The form contains a combination of CharFields and ModelMultipleChoiceField / ModelChoiceField, and when I try to set the form data in the session, I got a type error because the dict is not serializable:
Type Error: <Model: object> is not JSON serializable.
When I read about it and tried "django.contrib.sessions.serializers.PickleSerializer" it worked fine. But I don't want to use it after reading about this performance and security issues.
I'm new to Python-social-auth and this might not be the best approach for doing this. I wonder if there is a way to pass the form data into the pipeline without writing a custom serializer to save the user and profile.
Thanks for any help.
Edit
The way I dealt with this is redirecting the form form to the pipeline (partially) and not to the view. In the pipeline, I used request_data when POST request and form submit and set the profile form data in dict file. Probably not the best solution, but it worked for me.
source to share
No one has answered this question yet
See similar questions:
or similar: