我正在使用 devise用于身份验证。如何设置登录范围?例如,假设我只想对范围内的用户进行身份验证:
User.where(:active => true)
我说清楚了吗?这很简单,但如果需要,我可以详细说明。
(我知道有一个可锁定的模块,但我的实际范围不是针对活跃用户的,它更像是 current_site.users,其中 current_site 是基于域的)
最佳答案
只需在您的User 模型中重写这两个方法来检查事件标志是否为true:
# Called by Devise to see if an user can currently be signed in
def active_for_authentication?
active? && super
end
# Called by Devise to get the proper error message when an user cannot be signed in
def inactive_message
!active? ? :deactivated : super
end
然后在您的 devise.en.yml 中添加正确的错误消息:
devise:
failure:
deactivated: "Luke, I'm your father and your account was locked!"
关于ruby-on-rails - 设计 - 验证时设置范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5320200/