3

Following this tutorial, I setup a simple registration system with devise, where a user enters their email address, they are sent a confirmation email, they click on it, it takes them to a form where they have to enter their password and complete the registration.

How do I skip that password form so that once the user clicks on the confirmation link in their email, their account is created? How can I automatically set simple password for all users?

Katie H
  • 2,283
  • 5
  • 30
  • 51
  • I'd put an `after_create` hook in your `User` model to set the default password. But as for skipping the password input, I am not sure. – mc9 Feb 08 '15 at 20:42

1 Answers1

3

Create a method in your user model to use it instead of the create method. Let's call it create_with_password

def self.create_with_password(attr={})
   generated_password = attr[:first_name] + "123"
   self.create(attr.merge(password: generated_password, password_confirmation: generated_password))
end

Override devise's registration controller to use your new method which generates the two necessary fields for devise password and password_confirmation using the first_name attribute in your user model for example then 123 like in John123

In your controller after your parameters are sanitized. You should call User.create_with_password(user_params)

Oss
  • 4,232
  • 2
  • 20
  • 35
  • 3
    Actually it's better to use `generated_password = Devise.friendly_token.first(8)` for a generated password – Yurijmi May 13 '16 at 13:39
  • I would personally like to generate some thing more memory friendly strong entropy password with [xkpassword](https://github.com/jdeen/xkpassword) – Ziyan Junaideen May 19 '17 at 05:39