0

I'm using django-registration in my Django application with HMAC workflow. An email is sent with the activation link to the user after registration.

I'm using the versions bellow:

Django==1.11.1
django-registration==2.3

I saw here that there are two different views (function ou class) that could have being used. I put a breakpoint in the auth_urls.py and saw that in my application the registration.auth_urls_classes that are being used.

I've created a link to go to my reset password page:

<a class="g-font-size-12" href="{% url 'auth_password_reset' %}">Esqueceu a senha?</a>

This link sends to the template password_reset_form.html, it is in the image bellow:

{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="row justify-content-center g-py-180">
    <div class="col-sm-10 col-md-9 col-lg-4">
        <header class="text-center g-mb-30">
            <h2 class="h2 g-color-black g-font-weight-600"> Resete sua senha </h2>
        </header>
        <form method="post" action="{% url 'auth_password_reset' %}">
            <h1 class="h5 g-font-weight-300">Forneça seu endereço de email e nós enviaremos para você um link para alterar sua senha.</h1>


            {% csrf_token %}

            {% for field in form %}
                {% if field.name ==  'email' %}
                    <div class="mb-4 mt-4">
                      <input class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4
                         g-brd-primary--hover rounded g-py-15 g-px-15" type="email" required
                         placeholder="harry_potter@gmail.com" name="{{ field.html_name }}" id="{{ field.auto_id }}">
                    </div>
                {% endif %}
            {% endfor %}
            <button class="g-min-width-100x btn btn-md u-btn-primary rounded g-py-13 g-px-25" type="submit" value="Submit">Enviar email de redefinição de senha</button>
        </form>
    </div>
</div>
{% endblock %}

After typing the email address and send the form, the email is sent correctly (email arrived to me), but the error bellow occurrs:

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/password/reset/auth_password_reset_done

My urls are defined as bellow:

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),

    #authentication
    url(r'^accounts/', include('registration.backends.hmac.urls')),

    url(r'^profile/', include('pxgbr2.account_settings.urls', namespace='profile')),
    url(r'^admin/', admin.site.urls),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, 
document_root=settings.MEDIA_ROOT)

Note that the name of the success url (auth_password_reset_done') was "appended" in the link, instead of being replaced by the pattern. I couldn't figure out why, though.

B. Almeida
  • 377
  • 1
  • 11

1 Answers1

1

You appear to have hit this issue. There is a fix pull request #111 that you could try or it might be simpler to include Django's auth URLs yourself:

url('^accounts/', include('django.contrib.auth.urls')),
url('^accounts/', include('registration.backends.hmac.urls')),

The registration.auth_urls will be removed in django-registration 3.0, so including the auth urls separately is the best approach for the future.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • I've tried that already, and it worked in this case, but the same type of error occurs when sending the form in page 'password_reset_confirm.html', and I couldn't fix it, since when I put {% url 'password_reset_confirm' %} in this form it expects some parameters (token and uuid). That's why I'm looking for a solution using just the django-registration. I saw the pull request and looks like what I need. If it's the case, how could add it as dependence in my project without having any release of django-registration with this modification? – B. Almeida Dec 13 '17 at 15:43
  • 1
    See [this question](https://stackoverflow.com/questions/13561618/pip-how-to-install-a-git-pull-request) for how to install a pull request using pip. – Alasdair Dec 13 '17 at 16:03
  • 1
    Note that you *always* need token and uuid when reversing the `password_reset_confirm` view, it's [covered in the docs](https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.views.PasswordResetView). – Alasdair Dec 13 '17 at 16:18