自动为用户设置密码

编程入门 行业动态 更新时间:2024-10-28 08:24:23
本文介绍了自动为用户设置密码-设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

遵循本教程,我通过设计设置一个简单的注册系统,在该系统中,用户输入电子邮件地址,将向他们发送确认电子邮件,然后单击该电子邮件,将其带到一个表单,在该表单中,他们必须输入密码并完成注册.

如何跳过该密码表,以便一旦用户单击电子邮件中的确认链接,便创建了他们的帐户?如何为所有用户自动设置简单密码?

解决方案

在用户模型中创建一个方法来使用它,而不是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)) 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)

更多推荐

自动为用户设置密码

本文发布于:2023-10-20 01:02:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!