我有一个功能齐全的身份验证系统,其中包含一个包含五十多列的用户表。这很简单,但它使用盐进行哈希加密,使用电子邮件而不是用户名,并且还有两种不同类型的用户和管理员。
我希望将设计身份验证合并到我的应用程序中,以加强额外的部分,例如电子邮件验证、忘记密码、记住我的令牌等……我只是想看看是否有人在合并时遇到任何建议或问题设计成已经存在的用户结构。我的用户模型中的基本字段是:
t.string :first_name, :null => false
t.string :last_name, :null => false
t.string :email, :null => false
t.string :hashed_password
t.string :salt
t.boolean :is_userA, :default => false
t.boolean :is_userB, :default => false
t.boolean :is_admin, :default => false
t.boolean :active, :default => true
t.timestamps
作为参考,这里是迁移中的设计字段:
t.database_authenticatable :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
最终变成架构中的这些实际字段:
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "reset_password_token"
t.string "remember_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
大家有什么推荐的?我是否只是从我的迁移中删除电子邮件、hashed_password 和 salt,然后放入 5 个设计迁移字段,一切都会好起来的,还是我需要做其他事情?
编辑:
我自己已经开始尝试这个并且已经遇到了一些问题。我将上面显示的设计迁移字段添加到我现有的用户模型中,现在当我运行我的种子文件时,它给了我这个 Postgresql 错误:
ERROR: duplicate key value violates unique constraint "index_users_on_email"
我的种子文件:
initial_usersA = User.create!(
[
{
:first_name => "John",
:last_name => "Doe",
:email => "johndoe@gmail.com",
:is_userA => true,
:is_userB => false,
:is_admin => true,
:password => "password",
:password_confirmation => "password"
},
{
:first_name => "Jane",
:last_name => "Smith",
:email => "janesmith@gmail.com",
:is_userA => true,
:is_userB => false,
:is_admin => true,
:password => "password",
:password_confirmation => "password"
}
用户型号:
devise :registerable, :authenticatable, :recoverable,
:rememberable, :trackable, :validatable
attr_accessor :password_confirmation, :email, :password
堆栈跟踪显示,由于某种原因,电子邮件显然没有与其余变量一起输入......尽管种子文件中的所有其他内容都显示在实际查询中,但由于某种原因,电子邮件是 ''它是明确定义的.auth