django-password-reset
django-password-reset copied to clipboard
Provide API for generating a reset url outside of the Form/View Code
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]
)
Any progress here?
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).
Thanks @adamhaney, got it working, just had to update the salt value.
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.