alejandro zuleta
alejandro zuleta

Reputation: 14108

Password reset functionality Django-Registration-Redux app

I've installed Django-Registration-Redux app in my project and set up the default one step registration backend and it worked so far. Now i want to extend the functionality of my app by adding password change mechanism. How do I do this?

PD: Django-registration-redux documentation is not related to this topic.

Upvotes: 2

Views: 3671

Answers (3)

timotaoh
timotaoh

Reputation: 340

You can use the standard django.contrib.auth template tags and add auth_ to the beginning of the tag. Here is how auth_urls.py is set up in Django-Registration-Redux:

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.urls import reverse_lazy

urlpatterns = [
    url(r'^login/$',
        auth_views.LoginView.as_view(
            template_name='registration/login.html'),
        name='auth_login'),
    url(r'^logout/$',
        auth_views.LogoutView.as_view(
            template_name='registration/logout.html'),
        name='auth_logout'),
    url(r'^password/change/$',
        auth_views.PasswordChangeView.as_view(
            success_url=reverse_lazy('auth_password_change_done')),
        name='auth_password_change'),
    url(r'^password/change/done/$',
        auth_views.PasswordChangeDoneView.as_view(),
        name='auth_password_change_done'),
    url(r'^password/reset/$',
        auth_views.PasswordResetView.as_view(
            success_url=reverse_lazy('auth_password_reset_done')),
        name='auth_password_reset'),
    url(r'^password/reset/complete/$',
        auth_views.PasswordResetCompleteView.as_view(),
        name='auth_password_reset_complete'),
    url(r'^password/reset/done/$',
        auth_views.PasswordResetDoneView.as_view(),
        name='auth_password_reset_done'),
    url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        auth_views.PasswordResetConfirmView.as_view(
            success_url=reverse_lazy('auth_password_reset_complete')),
        name='auth_password_reset_confirm'),
]

Upvotes: 0

Niraj Kumar
Niraj Kumar

Reputation: 754

The book 'Tango With Django' by Leif Azzopardi and David Maxwell contains a nice example using 'Django-Registration-Redux app' in Chapter 11. This chapter explains in detail - the process to install/setup this module and configure settings, views & urls pattern in clear and concise manner.

According to the book, the module 'Django-Registration-Redux' does not provide templates for the urls it exposes. You need to create these templates manually - because these tend to be application specific. (You should create a directory named registration in your project's template directory to store these template files.) You should also see Anders Hofstee's Templates to take some hints to build your own templates. Mine is as follows (based on his template):

# <my_django_project_directory>/templates/accounts/password_change_form.html

{% extends "<my_app_name>/base.html" %}
{% block body_block %}
  <h1>Change your password</h1>
  <form method="post" action=".">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
  </form>
{% endblock %}

Assuming you have configured the module in the project's settings.py, you should include the following url in the url_patterns list found in your project's urls.py file-

url(r'^accounts/', include('registration.backends.simple.urls')),

As explained by the earlier answers, the url to change the password for a logged in user is http://<projects_root_url>/accounts/password/change. You should provide this url to the logged in user for access by updating the menu item. Continuing with the book's examples I have updated my base template to expose the Password Change url. Consider the following code:

# <my_django_project_directory>/templates/<my_app_name>/base.html
{% if user.is_authenticated %}
    <li><a href="{% url 'auth_logout' %}?next=/rango/">Logout</a></li>
    <li><a href="/accounts/password/change/">Change Password</a></li>
{% else %}
    <li><a href="{% url 'auth_login' %}">Login</a></li>
    <li><a href="{% url 'registration_register' %}">Sign Up</a></li>
{% endif %}

I hope this helps! If not, then I would highly recommend you to go through the book mentioned above! Easy examples, simple to understand instructions, and most importantly, the example works without putting too much effort in any configuration.

Note: Book examples are based on django version 1.9 . My OS is Ubuntu 16.04 and python version - 3.5.2 . My repository containing working example from the book.

Upvotes: 0

user61092
user61092

Reputation: 146

The django-registration-redux supports password change functionality too. For password change the url is http://your-port-number/accounts/password/change. In your localhost once you type in http://your-port-address/accounts/, you will get all the information regarding the url mappings on the screen itslef. Using those url mappings you can write specific html templates and use them in your app directly. The registration templates can be found here Hope this helps.

Upvotes: 4

Related Questions