def test_authenticated_user_is_redirected(self): request = self.factory.get('/alpha/') request.user = _get_auth_user_mock() view = decorators.not_auth_required(dummy_view) response = view(request, 'OK') eq_(response.status_code, 302) eq_(response['Location'], '/')
def test_unauth_user_request_is_successful(self): request = self.factory.get('/beta/') request.user = _get_non_auth_user_mock() view = decorators.not_auth_required(dummy_view) response = view(request, 'OK1') eq_(response, 'OK1')
account corresponding to that key (if possible). After successful activation, the signal ``registration.signals.user_activated`` will be sent, with the newly activated ``User`` as the keyword argument ``user`` and the class of this backend as the sender. """ activated_user = RegistrationProfile.objects.activate_user(activation_key) return activated_user def get_success_url(self, request, user): return ('registration_activation_complete', (), {}) # Registration views: # Using function aliases for lazy loadind and readability in the urls file. registration_view = decorators.not_auth_required( EmailRegistrationView.as_view()) registration_activation_complete = TemplateView.as_view( template_name='registration/activation_complete.html') # Using local ``Activation`` view to avoid sending duplicate # user_activated signals: registration_activate = ActivationView.as_view() registration_complete = TemplateView.as_view( template_name='registration/registration_complete.html') registration_disallowed = TemplateView.as_view( template_name='registration/registration_closed.html') @login_required def user_profile(request): """Edit the ``User`` owned ``Profile``.""" # Make sure the user has a profile:
name='registration_activation_complete'), # Activation keys get matched by \w+ instead of the more specific # [a-fA-F0-9]{40} because a bad activation key should still get to # the view; that way it can return a sensible "invalid key" message # instead of a confusing 404. url(r'^activate/(?P<activation_key>\w+)/$', 'registration_activate', name='registration_activate'), url(r'^register/complete/$', 'registration_complete', name='registration_complete'), url(r'^register/closed/$', 'registration_disallowed', name='registration_disallowed'), ) urlpatterns += patterns( 'django.contrib.auth.views', url(r'^login/$', decorators.not_auth_required(login), {'template_name': 'registration/login.html'}, name='auth_login'), url(r'^logout/$', 'logout', {'template_name': 'registration/logout.html'}, name='auth_logout'), url(r'^password/change/$', 'password_change', name='password_change'), url(r'^password/change/done/$', 'password_change_done', name='password_change_done'), url(r'^password/reset/$', 'password_reset', name='password_reset'), url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'password_reset_confirm', name='password_reset_confirm'), url(r'^password/reset/complete/$', 'password_reset_complete', name='password_reset_complete'), url(r'^password/reset/done/$', 'password_reset_done', name='password_reset_done'), )