1. David Marble
  2. django-registration


David Marble  committed f90a4d0 Merge

merge pull request for auto-login optional feature

  • Participants
  • Parent commits 5da97c0, c0d19e8
  • Branches default

Comments (0)

Files changed (2)

File docs/quickstart.rst

View file
 <http://docs.djangoproject.com/en/dev/topics/email/>`_ 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 ``manage.py syncdb`` to install the model
 used by the default setup.

File registration/signals.py

View file
+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)