Commits

James Bennett  committed 71601ba

Factor out the auth URLs into their own URLConf for easier including/reusability.

  • Participants
  • Parent commits fe454e9

Comments (0)

Files changed (2)

File registration/auth_urls.py

+"""
+URL patterns for the views included in ``django.contrib.auth``.
+
+Including these URLs (via the ``include()`` directive) will set up the
+following patterns based at whatever URL prefix they are included
+under:
+
+* User login at ``login/``.
+
+* User logout at ``logout/``.
+
+* The two-step password change at ``password/change/`` and
+  ``password/change/done/``.
+
+* The four-step password reset at ``password/reset/``,
+  ``password/reset/confirm/``, ``password/reset/complete/`` and
+  ``password/reset/done/``.
+
+The default registration backend already has an ``include()`` for
+these URLs, so under the default setup it is not necessary to manually
+include these views. Other backends may or may not include them;
+consult a specific backend's documentation for details.
+
+"""
+
+from django.conf.urls.defaults import *
+
+from django.contrib.auth import views as auth_views
+
+
+urlpatterns = patterns('',
+                       url(r'^login/$',
+                           auth_views.login,
+                           {'template_name': 'registration/login.html'},
+                           name='auth_login'),
+                       url(r'^logout/$',
+                           auth_views.logout,
+                           {'template_name': 'registration/logout.html'},
+                           name='auth_logout'),
+                       url(r'^password/change/$',
+                           auth_views.password_change,
+                           name='auth_password_change'),
+                       url(r'^password/change/done/$',
+                           auth_views.password_change_done,
+                           name='auth_password_change_done'),
+                       url(r'^password/reset/$',
+                           auth_views.password_reset,
+                           name='auth_password_reset'),
+                       url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
+                           auth_views.password_reset_confirm,
+                           name='auth_password_reset_confirm'),
+                       url(r'^password/reset/complete/$',
+                           auth_views.password_reset_complete,
+                           name='auth_password_reset_complete'),
+                       url(r'^password/reset/done/$',
+                           auth_views.password_reset_done,
+                           name='auth_password_reset_done'),
+)

File registration/backends/default/urls.py

 use a line like this in your root URLConf to set up the default URLs
 for registration::
 
-    (r'^accounts/', include('registration.backend.default.urls')),
+    (r'^accounts/', include('registration.backends.default.urls')),
 
 This will also automatically set up the views in
 ``django.contrib.auth`` at sensible default locations.
 
-But if you'd like to customize the behavior (e.g., by passing extra
+If you'd like to customize the behavior (e.g., by passing extra
 arguments to the various views) or split up the URLs, feel free to set
 up your own URL patterns for these views instead.
 
 
 from django.conf.urls.defaults import *
 from django.views.generic.simple import direct_to_template
-from django.contrib.auth import views as auth_views
 
 from registration.views import activate
 from registration.views import register
                            activate,
                            { 'backend': 'registration.backends.default.DefaultBackend' },
                            name='registration_activate'),
-                       url(r'^login/$',
-                           auth_views.login,
-                           {'template_name': 'registration/login.html'},
-                           name='auth_login'),
-                       url(r'^logout/$',
-                           auth_views.logout,
-                           {'template_name': 'registration/logout.html'},
-                           name='auth_logout'),
-                       url(r'^password/change/$',
-                           auth_views.password_change,
-                           name='auth_password_change'),
-                       url(r'^password/change/done/$',
-                           auth_views.password_change_done,
-                           name='auth_password_change_done'),
-                       url(r'^password/reset/$',
-                           auth_views.password_reset,
-                           name='auth_password_reset'),
-                       url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
-                           auth_views.password_reset_confirm,
-                           name='auth_password_reset_confirm'),
-                       url(r'^password/reset/complete/$',
-                           auth_views.password_reset_complete,
-                           name='auth_password_reset_complete'),
-                       url(r'^password/reset/done/$',
-                           auth_views.password_reset_done,
-                           name='auth_password_reset_done'),
                        url(r'^register/$',
                            register,
                            { 'backend': 'registration.backends.default.DefaultBackend' },
                            direct_to_template,
                            { 'template': 'registration/registration_closed.html' },
                            name='registration_disallowed'),
+                       (r'', include('registration.auth_urls')),
                        )