iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.62k stars 302 forks source link

having trouble with the password reset email that sends a URL. #549

Open avatarKaran opened 10 months ago

avatarKaran commented 10 months ago

I need the URL to be a custom URL not using the server. instead it should be for the front end .

how would I go about doing this?

SeaBebop commented 9 months ago

With reactjs I was able to use the /dj-rest-auth/password/reset/ endpoint to send an email to the user, which requires the user to input their email. After this dj-rest-auth sends the uid and token to the password reset email as stated by the document: image

This is important because now you can send a custom url using the given {{ token }} like in my example password_reset_key_message.html: image

Im assume this is what you mean because you need a server to send this token.

flange-ipb commented 9 months ago

@avatarKaran Take a look at the stack trace when having no view _password_resetconfirm defined (that's FAQ 2):

../../env/lib/python3.9/site-packages/dj_rest_auth/serializers.py:254: in save
    self.reset_form.save(**opts)
../../env/lib/python3.9/site-packages/dj_rest_auth/forms.py:64: in save
    url = url_generator(request, user, temp_key)
../../env/lib/python3.9/site-packages/dj_rest_auth/forms.py:23: in default_url_generator
    path = reverse(
../../env/lib/python3.9/site-packages/django/urls/base.py:88: in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)

forms.py:63 is url_generator = kwargs.get('url_generator', default_url_generator), so you can hook into that by manipulating kwargs. Fortunately, this can be achieved because PasswordResetSerializer.get_email_options() is added to those kwargs, so you just have to use a custom PasswordResetSerializer and override get_email_options().

flange-ipb commented 9 months ago

Second thought: Also take look at default_url_generator. I think you can also achieve your goal by using sites, the url definition for _password_resetconfirm and the setting ACCOUNT_DEFAULT_HTTP_PROTOCOL.