In my app for a certain use case I create a new user (programmatically set the password) and send them a confirmation email.
I would like them to be able to change their password immediately after confirming (without having to enter the system generated one which I don’t want to send them)
In effect I would like
1) System creates a new user account with generated password.
2) System sends confirmation email.
3) User clicks confirmation and is redirected to enter in their password (effectively send them to a URL like below)
<a href="http://localhost:3000/users/password/edit?reset_password_token=v5Q3oQGbsyqAUUxyqLtb">Change my password</a>
Any help / pointers would be great.
A simple way to have just one step for users to confirm email address and set initial password using the link you proposed…
Send one email your app generates, including a reset_password_token, and consider user’s possession of that token confirmation of the validity of that email address.
In system account generation code, assuming User model is set up with :recoverable and :database_authenticatable Devise modules…
Make the devise reset password view a little clearer for users when setting initial password.
views/devise/passwords/edit.html.erb
Generated Email
No need to include :confirmable Devise module in your User model, since accounts created by your app won’t get accessed without the reset_password_token in the email.
Devise will handle the submit and clear the reset_password_token field.
See
devise_gem_folder/lib/devise/models/recoverable.rbanddatabase_authenticatable.rbfor details onreset_password_tokenmethod and friends.If you want to use Devise
:confirmablemodule rather than this approach, see the Devise wiki page.