Skip to content

Instantly share code, notes, and snippets.

@jterrace
Created February 14, 2012 03:42
Show Gist options
  • Save jterrace/1823320 to your computer and use it in GitHub Desktop.
Save jterrace/1823320 to your computer and use it in GitHub Desktop.
Automatically log in user after django-registration activation
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)
@mazelx
Copy link

mazelx commented Jul 1, 2015

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.

@AbdAhmad
Copy link

AbdAhmad commented May 5, 2021

It says 'No module named 'registration'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment