django-password-reset icon indicating copy to clipboard operation
django-password-reset copied to clipboard

Provide API for generating a reset url outside of the Form/View Code

Open adamhaney opened this issue 7 years ago • 4 comments

I recently needed to send a user a reset email programmatically without going through the form request/response cycle. I ended up hacking together a function that generates a token/url but it'd be nice if there was a "blessed" way to do this from within the library.

This is what I came up with, is there a better way to do this and/or could I submit a patch with similar functionality?

from password_reset.views import SaltMixin

from django.core import signing


def get_password_reset_url(user):
    token = signing.dumps(user.pk, SaltMixin.salt)
    
    return reverse(
        'password_reset_reset',
        args=[token]
    )

adamhaney avatar Sep 17 '18 14:09 adamhaney

Any progress here?

pindaroso avatar Feb 12 '19 15:02 pindaroso

You can use that snippet, if there's interest I could open a PR with a utils.py that includes that above function (or some other API if anyone has input).

adamhaney avatar Feb 13 '19 22:02 adamhaney

Thanks @adamhaney, got it working, just had to update the salt value.

pindaroso avatar Feb 15 '19 15:02 pindaroso

I assume you need this for when an administrator creates a user account, but naturally wants the user to choose their password? I think this is a pretty common use case, so I suggest you create the pull request.

mscheper avatar May 06 '19 19:05 mscheper