遵循本教程,我通过设计设置一个简单的注册系统,在该系统中,用户输入电子邮件地址,将向他们发送确认电子邮件,然后单击该电子邮件,将其带到一个表单,在该表单中,他们必须输入密码并完成注册.
如何跳过该密码表,以便一旦用户单击电子邮件中的确认链接,便创建了他们的帐户?如何为所有用户自动设置简单密码?
解决方案在用户模型中创建一个方法来使用它,而不是create方法.我们称之为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重写devise的注册控制器,以使用您的新方法,该方法会使用用户模型中的first_name属性(例如,像John123中的123)生成用于设计password和password_confirmation的两个必要字段. >
在清除参数后,在控制器中.您应该致电User.create_with_password(user_params)
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)) endOverride 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)
更多推荐
自动为用户设置密码
发布评论