Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a password reset link to default admin login page if a password…

… reset URL is available.

You no longer have to override the admin login page just to get that link to
appear!

Also provided much better docs for how to plug in the provided password
reset mechanism with minimum effort.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17266 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1c169071998702880b4fa534c06b35c20f184eef 1 parent 14ba0df
Luke Plant authored December 24, 2011
3  django/contrib/admin/static/admin/css/login.css
@@ -52,3 +52,6 @@ body.login {
52 52
     padding: 1em 0 0 9.4em;
53 53
 }
54 54
 
  55
+.login .password-reset-link {
  56
+    text-align: center;
  57
+}
7  django/contrib/admin/templates/admin/login.html
... ...
@@ -1,5 +1,6 @@
1 1
 {% extends "admin/base_site.html" %}
2 2
 {% load i18n admin_static %}
  3
+{% load url from future %}
3 4
 
4 5
 {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}" />{% endblock %}
5 6
 
@@ -38,6 +39,12 @@
38 39
     <input type="hidden" name="this_is_the_login_form" value="1" />
39 40
     <input type="hidden" name="next" value="{{ next }}" />
40 41
   </div>
  42
+  {% url 'admin_password_reset' as password_reset_url %}
  43
+  {% if password_reset_url %}
  44
+  <div class="password-reset-link">
  45
+    <a href="{{ password_reset_url }}">{% trans 'Forgotten your password or username?' %}</a>
  46
+  </div>
  47
+  {% endif %}
41 48
   <div class="submit-row">
42 49
     <label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}" />
43 50
   </div>
5  docs/releases/1.4.txt
@@ -546,6 +546,11 @@ Django 1.4 also includes several smaller improvements worth noting:
546 546
   For more details, see the documentation for
547 547
   :meth:`~django.db.models.query.QuerySet.distinct`.
548 548
 
  549
+* The admin login page will add a password reset link if you include a URL with
  550
+  the name `'admin_password_reset'` in your urls.py, so plugging in the builtin
  551
+  password reset mechanism and making it available is now much easier. For
  552
+  details, see :ref:`auth_password_reset`.
  553
+
549 554
 Backwards incompatible changes in 1.4
550 555
 =====================================
551 556
 
28  docs/topics/auth.txt
@@ -371,6 +371,34 @@ Don't set the :attr:`~django.contrib.auth.models.User.password` attribute
371 371
 directly unless you know what you're doing. This is explained in the next
372 372
 section.
373 373
 
  374
+.. _auth_password_reset:
  375
+
  376
+User-requested password resets
  377
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  378
+
  379
+There is a bundled reset mechanism that integrates into the admin, allowing
  380
+users to reset their passwords by email. It can be customized and is described
  381
+in detail below under :func:`~django.contrib.auth.views.password_reset`. To
  382
+enable it without customization, add lines something like the following to your
  383
+urls.py:
  384
+
  385
+.. code-block:: python
  386
+
  387
+    url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='admin_password_reset'),
  388
+    (r'^admin/password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
  389
+    (r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
  390
+    (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
  391
+
  392
+(This assumes you've added the admin at ``admin/``, and requires that you put
  393
+the URLs starting with ``^admin/`` before the line that includes the admin app
  394
+itself).
  395
+
  396
+.. versionchanged:: 1.4
  397
+
  398
+The presence of the 'admin_password_reset' named URL will cause a "forgotten
  399
+your password?" link to appear on the default admin login page under the
  400
+password box.
  401
+
374 402
 .. _auth_password_storage:
375 403
 
376 404
 How Django stores passwords

0 notes on commit 1c16907

Please sign in to comment.
Something went wrong with that request. Please try again.