Rails 使用电子邮件和另一个字段设计身份验证
Rails Devise authentication with email and another field
使用 rails 设计。在用户 table 上,我有电子邮件和一个字段 record_status。记录状态将包含 'active' 或 'deleted'
我需要更改什么才能使用电子邮件进行身份验证,record_status = 'active'。
我有这个代码。
在我的用户模型中
def self.find_for_database_authentication(warden_conditions)
status = 'active'
where(:email => warden_conditions[:email], :record_status => warden_conditions[:status]).first
end
在我的初始化程序中 devise.rb
config.case_insensitive_keys = [:email]
感谢大家的帮助
有一个初始化程序用于设计其文件路径 config/initializers/devise.rb
ruffly 在第 37 行你应该看到
# config.authentication_keys = [:email]
现在您可以将其更新为
config.authentication_keys = [:email, :other_field]
Configuration for any authentication mechanism
Configure which keys are used when authenticating a user. The default is
just :email. You can configure it to use [:username, :subdomain], so for
authenticating a user, both parameters are required. Remember that those
parameters are used only when authenticating and not when retrieving from
session. If you need permissions, you should implement that in a before filter.
You can also supply a hash where the value is a boolean determining whether
or not authentication should be aborted when the value is not present.
使用 rails 设计。在用户 table 上,我有电子邮件和一个字段 record_status。记录状态将包含 'active' 或 'deleted'
我需要更改什么才能使用电子邮件进行身份验证,record_status = 'active'。
我有这个代码。
在我的用户模型中
def self.find_for_database_authentication(warden_conditions)
status = 'active'
where(:email => warden_conditions[:email], :record_status => warden_conditions[:status]).first
end
在我的初始化程序中 devise.rb
config.case_insensitive_keys = [:email]
感谢大家的帮助
有一个初始化程序用于设计其文件路径 config/initializers/devise.rb
ruffly 在第 37 行你应该看到
# config.authentication_keys = [:email]
现在您可以将其更新为
config.authentication_keys = [:email, :other_field]
Configuration for any authentication mechanism Configure which keys are used when authenticating a user. The default is just :email. You can configure it to use [:username, :subdomain], so for authenticating a user, both parameters are required. Remember that those parameters are used only when authenticating and not when retrieving from session. If you need permissions, you should implement that in a before filter. You can also supply a hash where the value is a boolean determining whether or not authentication should be aborted when the value is not present.