I'm trying to add change password functionality to a Django / React app. I'm using django-rest-passwordreset library for creating Reset or Forgot Password API using Django Rest Framework.
After I type the email that registered, I've managed get the token from the console
But I'm struggling to find a way to send an email to their email address with the link to reset their password along the given token. I've tried the SMTP Method or SendGrid. Was trying this way and this way
Can someone show me the correct way to make this work? Thanks a lot.
Edit :
Settings.py
INSTALLED_APPS = [
...
'rest_framework',
'django_rest_passwordreset',
]
Urls.py
from django.urls import path, include
urlpatterns = [
...
path('api/password_reset/', include('django_rest_passwordreset.urls', namespace='password_reset')),
]
Models.py
from django.dispatch import receiver
from django.urls import reverse
from django_rest_passwordreset.signals import reset_password_token_created
from django.core.mail import send_mail
@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):
email_plaintext_message = "{}?token={}".format(reverse('password_reset:reset-password-request'), reset_password_token.key)
send_mail(
# title:
"Password Reset for {title}".format(title="Astect"),
# message:
email_plaintext_message,
# from:
"astect@asei.co.id",
# to:
[reset_password_token.user.email]
)