Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial pipeline doesn't restore user model #198

Closed
w0rm opened this issue Feb 24, 2014 · 6 comments
Closed

Partial pipeline doesn't restore user model #198

w0rm opened this issue Feb 24, 2014 · 6 comments

Comments

@w0rm
Copy link
Contributor

w0rm commented Feb 24, 2014

Hello. You've made a really good library. I am not very experienced in Python, but it took me only one day to integrate social login into my small web.py app. Very productive!

Today I took another step and wanted to implement regular email+password login/registration. So I created two pipeline items: user_password and mail_validation that only work with email backend. The first one sets password for new user and validates password if user exists. It needs user model to exist, so I have placed it right after create_user. And the second one is partial, its a copy of default mail_validation except that it runs validation only for the new users.

I have a problem that user is not restored after resuming mail_validation partial pipeline, and if user is None then authentication doesn't happen. I've checked the code and found that user=user_id is saved to session with all data from partial pipeline, but then it is overridden by the user from do_complete call.

do_complete action has the following line

partial = partial_pipeline_data(strategy, user, *args, **kwargs)

And inside partial_pipeline_data is the code that replaces user from session with value passed from do_complete which may be None (please check my comments in the following bit of code):

    idx, backend, xargs, xkwargs = strategy.partial_from_session(partial)
    if backend == strategy.backend.name:
        kwargs.setdefault('pipeline_index', idx)
        kwargs.setdefault('user', user) # if I remove this line, then everything works
        kwargs.setdefault('request', strategy.request)
        print 'partial_pipeline_data before', xkwargs.get('user') # here user is present
        xkwargs.update(kwargs)
        print 'partial_pipeline_data after', xkwargs.get('user') # here user is None
        return xargs, xkwargs

Here is my complete 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.social_auth.associate_by_email',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'modules.social_auth.user_password',
'modules.social_auth.mail_validation', # <- this item is partial 
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
@gglentini
Copy link

Hi,
I have encountered exactly the same issue.

My pipeline is also very similar

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', 
    'profiles.pipeline.associate_by_email',   # custom association by mail
    'social.pipeline.user.create_user', 
    'profiles.pipeline.set_user_password',          
    'profiles.pipeline.mail_validation',            # send validation mail at signup
    'social.pipeline.social_auth.associate_user'
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details'
)

The problem seems starting in SHA: 228b36b.
I will try to debug or provide a pull request if I can.

Cheers

@w0rm
Copy link
Contributor Author

w0rm commented Feb 26, 2014

@gglentini seems to be it! This commit has changed user precedence so the user from session is overridden by the argument of partial_pipeline_data.

omab added a commit that referenced this issue Feb 27, 2014
@omab
Copy link
Owner

omab commented Feb 27, 2014

@w0rm, @gglentini could you try the fix above?

@w0rm
Copy link
Contributor Author

w0rm commented Feb 27, 2014

Should be working. I'm sorry I've already reorganised my pipeline so the user is created after email validation and password hash is set in details dict and copied to user on create_user step.

@gglentini can you check if it works in your implementation?

@gglentini
Copy link

Yep, I confirm the fix is properly working.
Thank you.

@omab
Copy link
Owner

omab commented Feb 28, 2014

Thanks, closing the issue.

@omab omab closed this as completed Feb 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants