0

I will be seeding my database with real people's names and email addresses, and inviting them to join the site by sending an email to the address that's in the database, with the link back to the site. If I use Devise's 'database_authenticable' with the site, it creates an email column and a column for an encrypted password. However, since I'm only seeding the database with an email, and not a password, I'm not sure if this will create problems.

Should I leave the password column blank? Should I create a dummy password and invite them to change it? Any recommendations?

When answering this question, please take note of my username on this site and provide the level of detail required for someone with my username (and others of similar intelligence) to understand your answer. Thank you in advance.

4

1 回答 1

0

做这样的事情的最简单的方法(不必对 Devise 本身感到困惑)是将密码设置为注册表单上的隐藏字段并为每个人设置默认值(例如 password123)

你需要运行

rails g devise:views

允许您自定义设计视图并将密码字段更改为隐藏字段。然后在您的用户模型中,指定您要设置密码的内容,例如

before_validation: set_default_password

def set_default_password
    self.password = 'password123'
    self.password_confirmation = 'password123'
end

然后修改设计电子邮件以告知用户他们的密码是什么,并建议他们尽快更改密码。

注意:这当然不是最好的解决方案,但它可能是最简单的运行而不会弄乱设计代码。

您可以查看的另一种选择是 devise_invitable gem...

https://github.com/scambra/devise_invitable

这允许您向用户电子邮件发送邀请,然后他们从那里设置密码。这可能不符合您的确切需求,但我认为值得一提。

相关的 SO 问题可以在这里找到....

设计:创建没有密码的用户然后需要密码才能使用帐户?

于 2013-01-18T21:02:18.660 回答