Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 946
Katie H Avatar asked Oct 21 '25 23:10

Katie H


1 Answers

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)

like image 62
Oss Avatar answered Oct 24 '25 14:10

Oss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!