Peter Lee
Peter Lee

Reputation: 13839

How to Verify Email Address for Forgot Password Feature in Ruby on Rails

I have implemented the Forgot Password feature, which will send a reset link to the user email. I also put some code to verify if it's a valid email address using a JavaScript library at the client side.

My question is how to check at the server side, so that when the email address is not in our database's users table, we will display a flash error message; If it is in our users table, we will send out the password reset link.

I'm using Devise for user management.

Upvotes: 0

Views: 746

Answers (1)

zeantsoi
zeantsoi

Reputation: 26193

The precise functionality you've depicted ships with Devise. To enable it, you'll need to declare your Devise model as being :recoverable:

# app/models/user.rb (assuming that User is a Devise model)
devise :database_authenticatable, :registerable,
       :rememberable, :trackable, :validatable, :recoverable

Then, you can access the password recovery form by visiting http://yourdomain/users/password/new. Presuming you haven't overridden/subclassed Devise::PasswordsController, you'll be granted all the functionality you need directly out-of-the-box.

Upvotes: 2

Related Questions