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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.