2
votes

I am developing a Rails 3.2 app. When a user signs up or when I create a user account in my admin panel, a welcome email is sent to them. I want to include a link on which the user can click to get to the password reset page (where they can set/change their password).

So what I want to do basically is to manually create a reset password token, create a link to the reset password page (where they select a new password) and include it in the welcome email. I do not want to send two emails (welcome and reset password).

I guess some of this code could be used but I do not know how.

https://github.com/plataformatec/devise/blob/master/lib/devise/models/recoverable.rb

How can I do this?

Thankful for all help!

1

1 Answers

0
votes

Just had to do something similar to this and thought I'd post an answer if someone stumbles on this. Assuming you have devise correctly set up, all you need to do is make sure the user exists in the database and then redirect to the devise route. I leveraged their code here: goo.gl/cE5USm.
def password_reset_controller user = User.find_by_email( params[:email] ) if user redirect_to password_path(:user, email: user.email) else # do something different end end In console if you call password_path(:user, email: user.email) -> "/users/password?email='email'"

Edit: Alternatively, you can just use user.send_reset_password_instructions from goo.gl/aPQ8MU