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

Add a way to know when a user is created with the request #50

Closed
thoas opened this issue Apr 14, 2011 · 1 comment
Closed

Add a way to know when a user is created with the request #50

thoas opened this issue Apr 14, 2011 · 1 comment

Comments

@thoas
Copy link

thoas commented Apr 14, 2011

Hi again,

I need to know when a user is created by the authenticate method of the SocialAuthBackend.

Use case: when a user is automatically created by django-social-auth, I write a specific message (with the help of the messages framework) which can be only done in a request context.

I know there is a signal named socialauth_registered which is launched when a user is created but for the need of my application I have to interact with the request object.

When I look into the authenticate method of the SocialAuthBackend I find the is_new variable which is True when a user is created.

Is there any way to return this value in the authenticate process?

I also have a quick solution based on django.contrib.auth.backends.authenticate which can be done in l.150 of social_auth/backends/init.py:

user.is_new = is_new
return user

Thanks again.

@omab
Copy link
Owner

omab commented Apr 14, 2011

You could do that on the signal level too

def new_user(sender, user, response, details, **kwargs):
    user.is_new = True
    return False  # to avoid the unnecessary user.save()

socialauth_registered.connect(new_user)

@omab omab closed this as completed Apr 14, 2011
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

2 participants