You will have to customize a pipeline method or add a new one to the pipeline.
For example, you could customize a create_user
method:
def create_user(strategy, details, user=None, *args, **kwargs):
email = details.get('email', '')
if UserClass.objects.filter(email=email).exists():
// do whatever you want
if user:
return {'is_new': False}
fields = dict((name, kwargs.get(name) or details.get(name))
for name in strategy.setting('USER_FIELDS',
USER_FIELDS))
if not fields:
return
return {
'is_new': True,
'user': strategy.create_user(**fields)
}
then in your settings file, indicate a path to this method:
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',
'path.to.your.custom.create_user', // indicate the path here
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)
hope this helps
UPDATE:
If you are not getting email
in the details
parameter, try this:
Print the response
variable in social_details
method of pipeline:
def social_details(backend, details, response, *args, **kwargs):
print response
return {'details': dict(backend.get_user_details(response),
**details)}
see in the logs if response contains email
. If it does contain email
, it means that email
is just not being included in the details
parameter in details
variable.
If not, is SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
working? I mean, is Facebook asking you to grant this scope when you login?
If yes, grant it. If no, try to delete your app from facebook, and register again. It sometimes happens.