@@ -125,3 +125,42 @@ The code for the project is available under the
125125~~ " traceback" ])
126126~~ task_finished = Signal(providing_args = [" process" , " task" ])
127127```
128+
129+
130+ ## Example 5 from django-registration (redux)
131+ [ django-registration (redux)] ( https://github.com/macropin/django-registration )
132+ ([ project documentation] ( https://django-registration-redux.readthedocs.io/en/latest/ ) )
133+ is a [ Django] ( /django.html ) code library for one-phase, two-phase and
134+ three-phase registration flows. The code is available
135+ [ open source] ( https://github.com/macropin/django-registration/blob/master/LICENSE ) .
136+
137+ [ ** django-registration / registrations / signals.py** ] ( https://github.com/macropin/django-registration/blob/master/registration/signals.py )
138+
139+ ``` python
140+ from django.conf import settings
141+ from django.contrib.auth import get_backends
142+ from django.contrib.auth import login
143+ ~~ from django.dispatch import Signal
144+
145+ # An admin has approved a user's account
146+ ~~ user_approved = Signal(providing_args = [" user" , " request" ])
147+
148+ # A new user has registered.
149+ ~~ user_registered = Signal(providing_args = [" user" , " request" ])
150+
151+ # A user has activated his or her account.
152+ ~~ user_activated = Signal(providing_args = [" user" , " request" ])
153+
154+
155+ def login_user (sender , user , request , ** kwargs ):
156+ """ Automatically authenticate the user when activated """
157+ backend = get_backends()[0 ] # Hack to bypass `authenticate()`.
158+ user.backend = " %s .%s " % (backend.__module__ , backend.__class__ .__name__ )
159+ login(request, user)
160+ request.session[' REGISTRATION_AUTO_LOGIN' ] = True
161+ request.session.modified = True
162+
163+
164+ if getattr (settings, ' REGISTRATION_AUTO_LOGIN' , False ):
165+ user_activated.connect(login_user)
166+ ```
0 commit comments