[英]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. 在用户模型中创建一个方法以使用它而不是
create
方法。 Let's call it create_with_password
我们称之为
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
覆盖devise的注册控制器以使用新方法,该方法使用用户模型中的
first_name
属性生成设计password
和password_confirmation
的两个必要字段,例如123
如John123
In your controller after your parameters are sanitized. 在对参数进行消毒后,在控制器中。 You should call
User.create_with_password(user_params)
你应该调用
User.create_with_password(user_params)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.