question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get password reset to work by following example

See original GitHub issue

Hi, I can’t get password reset to work. I’ve copied urls.py directly from the demo on GitHub:

# api/urls.py
from django.urls import include, path
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import TemplateView, RedirectView

from django.contrib.auth.views import PasswordResetView, \
    PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name="home.html"), name='home'),
    url(r'^signup/$', TemplateView.as_view(template_name="signup.html"),
        name='signup'),
    url(r'^email-verification/$',
        TemplateView.as_view(template_name="email_verification.html"),
        name='email-verification'),
    url(r'^login/$', TemplateView.as_view(template_name="login.html"),
        name='login'),
    url(r'^logout/$', TemplateView.as_view(template_name="logout.html"),
        name='logout'),
    url(r'^password-reset/$',
        TemplateView.as_view(template_name="password_reset.html"),
        name='password-reset'),
    url(r'^password-reset/confirm/$',
        TemplateView.as_view(template_name="password_reset_confirm.html"),
        name='password-reset-confirm'),

    url(r'^user-details/$',
        TemplateView.as_view(template_name="user_details.html"),
        name='user-details'),
    url(r'^password-change/$',
        TemplateView.as_view(template_name="password_change.html"),
        name='password-change'),


    # this url is used to generate email content
    url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        TemplateView.as_view(template_name="password_reset_confirm.html"),
        name='password_reset_confirm'),

    url(r'^rest-auth/', include('rest_auth.urls')),
    url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
    url(r'^account/', include('allauth.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=True), name='profile-redirect')
]

I’ve copied the Templates folder from the demo into my django project folder.

This is from my settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'rest_auth.registration',
    'api',
    'users',
]

AUTH_USER_MODEL = 'users.CustomUser'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# 
SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

When I browse to the endpoint http://127.0.0.1:8000/api/v1/rest-auth/password/reset/ I see a form with this information and an input to type an email:

GET /api/v1/rest-auth/password/reset/
HTTP 405 Method Not Allowed
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Method \"GET\" not allowed."
}

If I enter an email address and click “Post” the page changes to show

{
    "detail": "Password reset e-mail has been sent."
}

However no email text appears in the console.

Here’s the request that was sent, copied from the Network tab of the browser as cURL:

curl 'http://127.0.0.1:8000/api/v1/rest-auth/password/reset/' -H 'Cookie: tabstyle=html-tab; sessionid=n2nddatqzw71xiskvrn4kaynf2w6eq3x; csrftoken=ON4EIciQ7TawRpWH4g3qfh030tzHBnvQJFUZBxCMfQHn6xEgInj3ip5QCXX9r1HK' -H 'Origin: http://127.0.0.1:8000' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarygXpeN1siqg1pdzU8' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://127.0.0.1:8000/api/v1/rest-auth/password/reset/' -H 'Connection: keep-alive' --data-binary $'------WebKitFormBoundarygXpeN1siqg1pdzU8\r\nContent-Disposition: form-data; name="csrfmiddlewaretoken"\r\n\r\nGFZOPWrxqc3lpAyBaycV8IFtAuxp3jfbBxP9IhLty9AcEIgaOFsybQKgcYVRTXr5\r\n------WebKitFormBoundarygXpeN1siqg1pdzU8\r\nContent-Disposition: form-data; name="email"\r\n\r\nmy_name@adomain.com\r\n------WebKitFormBoundarygXpeN1siqg1pdzU8--\r\n' --compressed

If I paste that into a terminal, I get back the html for the password reset page.

Please, can you explain what I am missing to get this basic feature working?

Thank you.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

2reactions
s-sebastiancommented, Jan 17, 2019

Yes, use your custom user model.

Check the actual email backend:

$ python manage.py diffsettings --all | grep "EMAIL_BACKEND"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

You can also test it in the console:

>>> from django.core.mail import send_mail
>>> from django.conf import settings
>>> send_mail('Testing', 'This is a test message.', settings.DEFAULT_FROM_EMAIL, ['test01@example.com'], fail_silently=False)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Testing
From: webmaster@localhost
To: test01@example.com
Date: Thu, 17 Jan 2019 14:41:22 -0000
Message-ID: <154773608251.22695.3450121301521051516@exmaple.com>

This is a test message.
-------------------------------------------------------------------------------
1
1reaction
Shelagh-Lewinscommented, Jan 17, 2019

Thank you for your reply. I’ve got it working in in the end by changing a lot of things, so I can’t really retest this. But I wonder if the demo code is out of date? Maybe rest-framework has changed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot password resets blocked by on-premises policy
Enter a temporary password for the user to use. Select the Reset password button. In this scenario, you receive the following error message:....
Read more >
I Can't Reset My Password - When I Work Help Center
If your email address is incorrect in When I Work, or if you enter the wrong email address, you won't be able to...
Read more >
Reset a user's password - Google Workspace Admin Help
Change a password · In the Admin console, go to Menu · In the Users list, find the user. · Point to the...
Read more >
Password reset email: best practices + checklist & template
Password reset emails are one of the most common kinds of email. ... Ideally, they'd have access to several options for support to...
Read more >
Error 'Your password cannot be reset at this time' when you try ...
When a User resets their password, in some scenarios, they may receive an email containing the following error instead of a standard ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found