Created
February 14, 2012 03:42
-
-
Save jterrace/1823320 to your computer and use it in GitHub Desktop.
Automatically log in user after django-registration activation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from registration.signals import user_activated | |
from django.contrib.auth import login, authenticate | |
def login_on_activation(sender, user, request, **kwargs): | |
"""Logs in the user after activation""" | |
user.backend = 'django.contrib.auth.backends.ModelBackend' | |
login(request, user) | |
# Registers the function with the django-registration user_activated signal | |
user_activated.connect(login_on_activation) |
Thanks for this. Succinct and easy to understand.
Thanks for this; I also didn't know where to put the signal.
Why do you need to specify user.backend
here?
Thanks a lot ! Still works in Registration-Redux. Should definitively be integrated into standard registration-redux.
User received through signal does not contain any auth backend, that's why you need to specify it in that code.
It says 'No module named 'registration'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works for me, though I did it using a decorator. Did you make sure the code is loaded? For example, you could put it in the
models.py
for an installed app.