David Marble committed f90a4d0 Merge

merge pull request for auto-login optional feature

Comments (0)

Files changed (2)


 <>`_ for details).
-Required settings
 Begin by adding ``registration`` to the ``INSTALLED_APPS`` setting of
 your project, and specifying one additional setting:
     that period, the account will remain permanently inactive and may
     be deleted by maintenance scripts provided in django-registration.
+    Optional. If this is `True`, your users will automatically log in when they
+    click on the activation link in their email. Defaults to `False`.
 For example, you might have something like the following in your
 Django settings file::
     ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
+    REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.
 Once you've done this, run `` syncdb`` to install the model
 used by the default setup.


+from django.conf import settings
+from django.contrib.auth import login, get_backends
 from django.dispatch import Signal
 # A user has activated his or her account.
 user_activated = Signal(providing_args=["user", "request"])
+def log_in_user(sender, user, request, **kwargs):
+    if settings.get('REGISTRATION_AUTO_LOGIN', False):
+        backend = get_backends()[0] # A bit of a hack to bypass `authenticate()`.
+        user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
+        login(request, user)