Skip to main content

Easily add password reset workflows to your django project.

Project description

This app simplifies the process for adding password reset functionality to your site. It takes advantage of django’s exising password reset workflow, but simplifies the process of adding urls to your site. This also allows you to create multiple password reset workflows for one site using namespacing.

Installation

Just add “passreset” to INSTALLED_APPS, and include passreset.urls in your urlconf module:

from django.conf.urls import url, include
import passreset
urlpatterns = [
    #...
    url(r'^profile/passreset/', include(passreset.urls))
]

You can then link to the password reset form by reversing “passreset:reset-password”:

<a href="{% url "passreset:reset-password" %}">Forgot password?</a>

The app takes care of the rest, with the help of django’s built-in password reset workflow. Note that passreset.urls an object, not a module. Using include(‘passreset.urls’) will raise an ImportError.

To quickly add password reset functionality to your existing admin, just include passreset.admin_urls:

from django.conf.urls.defaults import url, include
import passreset

urlpatterns = [
  url(r'^admin/passreset/', include(passreset.admin_urls),
  url(r'^admin/', include(admin.site.urls)),
)

As an added convenience, the passreset app automatically overrides the default admin site’s login template to add a “forgot password?” link.

Namespacing

If you need multiple password-reset workflows for one site, you must use the passreset.urls_ns() function. Note that you should not use the namespace keyword argument to include:

import passreset
urpatterns = [
    url(r'^profile/reset-password', include(passreset.urls_ns(
        'user-passreset', login_url='/profile/login'))),
    url(r'^staff/reset-password', include(passreset.urls_ns(
        'staff-passreset', login_url='/staff/loging'))),
]

If login_url is not supplied, settings.LOGIN_URL is used. You can also pass a template_path argument to specify a base path for templates used in the app instance.

You can then reverse any of the passreset urls using the new namespace:

<a href="{% url "staff-passreset:reset-password" %}">Forgot password?</a>

Templates

The default templates form passreset all extend “passreset/base.html”, You can create an override for this template in your project (eg, my_project/templates/passreset/base.html), and have it extend your site’s base template. The templates all use a block called passreset_content. So, all you need to do is include that block inside your site’s main content block:

{% extends "mysite/base.html" %}
{% block content %}
  {% block passreset_content %}
  {% endblock %}
{% endblock %}

The urls_ns function also accepts a tpl_path parameter, which allows you to override any of the templates used by passreset. The path is a template directory that may contain any of the following:

  • reset_password.html

  • done.html

  • confirm.html

  • complete.html

  • email.html

  • subject.ttx

Admin

The passreset.admin_urls urlconf is basically a convenience shortcut for passreset.urls_ns(‘admin-passreset’, login_url=’admin:login’). As stated above, passreset overrides the default admin login template with a “Forgot password?” link, which basically looks like this:

<a href="{% url admin-passreset:reset-password }">Forgot password?</a>

You can use the admin passreset urls together with another passreset instance without using namespacing:

urlpatterns += patterns('',
  url(r'^admin/passreset/', include(passreset.admin_urls)),
  url(r'^admin/', include(admin.site.urls)),
  url(r'^profile/passreset', include('passreset.urls')),
)

Project details


Release history Release notifications | RSS feed

This version

0.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-passreset-0.3.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file django-passreset-0.3.tar.gz.

File metadata

File hashes

Hashes for django-passreset-0.3.tar.gz
Algorithm Hash digest
SHA256 213d437cf6a3d4ebc2788c6d6e0a82916c183a1ae25dbde216f73d753b45f1d4
MD5 278cd4214805b74c721ecc3f3a18af40
BLAKE2b-256 435cf41fb6a04e5a10f74dd6dfec0c2960f0865e9dae237c98ac4f829971a687

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page