I have a DRF server, and I've been trying to send a password reset email, using the PasswordResetForm.
I receive an email as expected, though when trying to send a reset the password, I receive:
{
"uid": [
"Invalid value"
]
}
After some investigation, I've found that in Django's PasswordResetConfirmSerializer's file, there is a conditional import which is responsible for the issue - I'm using allauth and so it imports the wrong uid_decoder module (it works using the other module):
# this imports the wrong uid_decoder
if 'allauth' in settings.INSTALLED_APPS:
from allauth.account.forms import default_token_generator
from allauth.account.utils import url_str_to_user_pk as uid_decoder
else:
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import urlsafe_base64_decode as uid_decoder
Is there a better way to handle the issue than editing the dj_rest_auth file?
Thanks!
Email send code, if needed:
from django.conf import settings
from django.contrib.auth.forms import PasswordResetForm
def send_user_invite(email):
# send invitation to reset password & join the platform
form_options = {
"use_https": True,
"from_email": getattr(settings, "DEFAULT_FROM_EMAIL"),
# "request": request,
"subject_template_name": "registration/password_reset_subject.txt",
"email_template_name": "users/invite_with_password_reset.html",
"extra_email_context": {"reset_base_url": settings.RESET_BASE_URL},
}
form = PasswordResetForm(data={"email": email})
if form.is_valid():
form.save(**form_options)