Skip to content

Commit

Permalink
Allow customizing password reset confirm URL (#487)
Browse files Browse the repository at this point in the history
Co-authored-by: urbsny <16968591+urbsny@users.noreply.github.com>
  • Loading branch information
c-w and urbsny committed Feb 21, 2023
1 parent 62c1dc9 commit 70089a3
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions dj_rest_auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
from allauth.utils import build_absolute_uri


def default_url_generator(request, user, temp_key):
path = reverse(
'password_reset_confirm',
args=[user_pk_to_url_str(user), temp_key],
)

if api_settings.PASSWORD_RESET_USE_SITES_DOMAIN:
url = build_absolute_uri(None, path)
else:
url = build_absolute_uri(request, path)

url = url.replace('%3F', '?')

return url


class AllAuthPasswordResetForm(DefaultPasswordResetForm):
def clean_email(self):
"""
Expand All @@ -44,17 +60,8 @@ def save(self, request, **kwargs):
# password_reset.save()

# send the password reset email
path = reverse(
'password_reset_confirm',
args=[user_pk_to_url_str(user), temp_key],
)

if api_settings.PASSWORD_RESET_USE_SITES_DOMAIN:
url = build_absolute_uri(None, path)
else:
url = build_absolute_uri(request, path)

url = url.replace("%3F", "?")
url_generator = kwargs.get('url_generator', default_url_generator)
url = url_generator(request, user, temp_key)

context = {
'current_site': current_site,
Expand Down

0 comments on commit 70089a3

Please sign in to comment.