Zab*_*bba 141
像这样做:
创建一个is_active为User模型调用的列.
然后将以下代码添加到User模型中:
class User < ActiveRecord::Base
#this method is called by devise to check for "active" state of the model
def active_for_authentication?
#remember to call the super
#then put our own check to determine "active" state using
#our own "is_active" column
super and self.is_active?
end
end
Run Code Online (Sandbox Code Playgroud)
UPDATE
正如Matt Huggins所说,这个方法现在被称为active_for_authentication?(文档)
小智 16
在User模型中添加一列:allowed_to_log_in.
然后将其添加到/app/models/user.rb:
def active_for_authentication?
super and self.allowed_to_log_in?
end
Run Code Online (Sandbox Code Playgroud)
如果您想通过自定义消息通知用户,您也可以添加此消息:
def inactive_message
"You are not allowed to log in."
end
Run Code Online (Sandbox Code Playgroud)
我认为这非常重要,因为Devise的标准信息说:
"您的帐户尚未激活."
这对用户来说很困惑,真正的原因是你已经"禁止"他们登录.