简体   繁体   中英

Automatically set password for user - Devise

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM