Thanks for comments and suggestions. I realized how to resolve my problem, and this is my solution, hope it helps to others.
The first problem is that PSA uses the same pipeline for both:
- registering new users and
- login existing ones.
So, it's mandatory differentiate one pipeline flow form the other. This can be done (have to be done?) arranging the query string:
<a href="{% url 'social:begin' 'facebook' %}?register=1">
, for Sign up.<a href="{% url 'social:begin' 'facebook' %}">
, for regular Login.
The second problem is how to read the register
parameter in the PSA pipeline. This task have to be done setting FIELDS_STORED_IN_SESSION
(see the PSA docs):
# settings.py
...
FIELDS_STORED_IN_SESSION = ['register']
Finally, my pipeline looks like this:
# settings.py
...
SOCIAL_AUTH_PIPELINE = (
'my.path.custom_pipeline.clean_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',
'my.path.custom_pipeline.redirect_to_join_form',
...
)
And my custom tasks:
# custom_pipeline.py
from social.pipeline.partial import partial
from django.contrib import messages
from django.shortcuts import redirect
def clean_pipeline(strategy, *args, **kwargs):
_register = strategy.session.get('register', None)
strategy.session.flush()
strategy.session['register'] = _register
@partial
def redirect_to_join_form(strategy, details, user=None, is_new=False, *args, **kwargs):
if user and user.username:
return
if is_new and strategy.session_get('register', False) == '1':
strategy.session.pop('register')
return redirect('users_join_form')
if is_new and strategy.session_get('saved_username'):
return {'username': strategy.session_get('saved_username')}
messages.add_message(
strategy.request, messages.ERROR,
"Error. Account not registered %s (%s), " %
(strategy.backend.name.capitalize(), details['username'])
)
return redirect('users_login')
That's all. Hope it helps.