How to get password reset url in devise?
The reset password url was formed by reset_password_token
in User
model.
So saving the reset_password_token
is enough to recover reset password url
later on.
reset_password_token = 'XYZ' # Example token
reset_password_url = Rails.application.routes.url_helpers.edit_user_password_path(reset_password_token: reset_password_token)
Due to security (an attacker could read the link from the database to bypass email verification), what Devise stores in user.reset_password_token
is only a digest of the token that is sent into the password reset link.
Specifically, in the set_reset_password_token
method, the enc
oded token is saved to the database, while the raw
token is returned and then sent in the password reset email.
What you can do is to reset the token yourself and save the raw token somewhere to be used later:
raw = user.send(:set_reset_password_token)
It's also worth noting that you can customize the devise mailer and provide your own templates. However, in this case, it would also affect the legitimate password reset emails.