Amro Abdalla
Amro Abdalla

Reputation: 584

Devise finding user by reset token

I'm trying to make an api for resetting password, I made devise handle the part when the user press on forgot password and sending him an email with a token but I tried to change it in the other part I needed to look up user using that token when he reset his password but Devise reset_password_token of the user (in the DB) is not like the token sent in the email, I only receive token, password, password_confirmation to make that API work, So I need to find that user using token sent in the email(User.where(reset_password_token: TOKEN)), Is there a way to convert token in the email to the one I have in the DB.

Upvotes: 0

Views: 1667

Answers (1)

apneadiving
apneadiving

Reputation: 115531

You have to check the reset_password_by_token class method which contains the logic. But you can use it directly:

User.reset_password_by_token({
  reset_password_token: token,
  password: password,
  password_confirmation: password_confirmation
})

Link to current master code here

Upvotes: 3

Related Questions