Skip to main content

This is an easy to include library that takes care of managing the reset password part of your application. It offers 3 endpoints used for creating, validating and submitting the password change. The user if offered the liberty to chose how the reset password link is sent to the user and where it will redirect the user.

Requirements

Python >= 3.7 Django >=3.0

We highly recommend and only officially support the latest patch release of each Python and Django series

Installation

The command to install the package from pypi using pip:

` pip install drf-reset-password `

Add reset-password to your INSTALLED_APPS in settings

INSTALLED_APPS=[
    ...,
    'reset_password',
    ]

Configuration

You can configure the library from the variable DRF_RESET_EMAIL that you will set in your settings.

{
    'RESET_PASSWORD_EMAIL_TITLE': 'Reset Password',
    'RESET_PASSWORD_EMAIL_TEMPLATE': 'reset_email.html',
    'EMAIL_EXPIRATION_TIME': 24,
    'REDIRECT_LINK': 'dsa',
    'APP_NAME': 'test',
    'EMAIL_PROVIDER': 'reset_password.models.EmailProvider',
    'CONTENT_PROVIDER': 'reset_password.models.DefaultContentProvider',
    'EMAIL_FIELD': 'email',
    'CUSTOM_PASSWORD_SET': False,
}

RESET_PASSWORD_EMAIL_TITLE - Sets the title of the email sent. RESET_PASSWORD_EMAIL_TITLE is on default on Reset Password.

RESET_PASSWORD_EMAIL_TEMPLATE - You can change the default template with your own template.``RESET_PASSWORD_EMAIL_TEMPLATE`` is on default on our default template.

EMAIL_EXPIRATION_TIME - The amount of time it takes for the email to expire. EMAIL_EXPIRATION_TIME is on default on 24 hours.

REDIRECT_LINK - The url of your redirect link inside the email (you can access it inside your own template with the variable link).

APP_NAME - The name of you app that will be mentioned inside the email.

EMAIL_PROVIDER - The class which will be called to send the email (The class has to extend the class EmailProvider and implement the method send_email).

EMAIL_FIELD - This is the field on the user that contains the email. If you are using django a user model you should always have it on email. EMAIL_FIELD is on default on email.

CONTENT_PROVIDER - The class which will be called to build the content of the email (The class has to extend the class ContentProvider and implement the method make_content.). If none set, a DefaultContentProvider will be set, creating content with the above specified details (template, link, etc.).

CUSTOM_PASSWORD_SET - A boolean variable which tells if the password should be saved in a custom way, when catching the custom_password_update signal (True), or, in the default way (False). Note that the status of the token should also be set to ACCEPTED if the password was set successfully.

RETURN_EMAIL_NOT_FOUND_ERROR - A boolean which specifies if the reset password request should return a 400 error if the email does not exist in the system. The default value is True. If set to False, the endpoint will return a 201 status code

Template Creation

This is an example on how your template should look we give you 3 variables that you can access. Which are app_name, link and email (this is the email of the user which had his password changed).

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
  <p>Hello,</p>
  <p>Follow this link to reset your {{ app_name }} password for your {{ email }} account.</p>
  <p><a href='{{ link }}'>{{ link }}%</a></p>
  <p>If you didn’t ask to reset your password, you can contact us.</p>
  <p>Thanks,</p>
  <p>Your {{ app_name }} team</p>
</body>
</html>

Final steps for set up

When you are done with configuring your reset_password app you can add it to your urls and start making calls.

from django.conf.urls import url
from django.urls import include
from rest_framework import routers
from reset_password.views import ResetPasswordView

router = routers.DefaultRouter(trailing_slash=False)
router.register("reset-password", ResetPasswordView, basename="reset_password")
urlpatterns = [
    ...,
    url(r"^", include(router.urls)),
]

Endpoints

The app has 3 endpoints: one for generating the email for reset password, one for validating the token inside the email and one for changing the password.

Create Endpoint

This endpoint receives the email address and creates and calls for the EMAIL_PROVIDER to send the email to the user.

reset-password/ -> POST
{
  "email": "example@google.com"
}

It has an empty response with 201 if successful and 400 if email is not valid.

Token Validation

This endpoint receives the token through the query param token and it verifies if it is valid.

reset-password/token-validation -> POST
{

}

It has an empty response with 200 if successful and 400 if token is not valid.

Change Password

This endpoint receives the token through the query param token and it verifies if it is valid. and then changes the user’s password with the one sent in the body

reset-password/submit -> POST
{
  "password": "password"
}

It has an empty response with 200 if successful and 400 if token is not valid or the password sent.

Good luck using it and if you have any question or suggestions please contact us

Release files for drf-reset-password 1.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-reset-password 1.2.9
File Size Uploaded
drf-reset-password-1.2.9.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-reset-password 1.2.9
File Interpreter ABI Platform
drf_reset_password-1.2.9-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / drf-reset-password-1.2.9.tar.gz

Download URL drf-reset-password-1.2.9.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b12976782e4fd862cff4afec248fee5b9c46516f75d334db9e93a1195b6256e8
BLAKE2b-256 checksum
How to use checksums
d49c71e4442f723aa6f077addbc4b2d6d2ba277b810faa7267e6f6cdcdc64bb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.0

Release files / drf_reset_password-1.2.9-py3-none-any.whl

Download URL drf_reset_password-1.2.9-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b1b89e639e0eb765d97deea5260526f2919f691bb19185e7c57e99792c0b64e
BLAKE2b-256 checksum
How to use checksums
7f2b9a5ff4ba22d758b3e142a56cb1cde2499ab4bcacb73db6b19bad156b5d68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.2.9 This release

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page