繁体   English   中英

Rails-Devise:检查用户是否可以登录

[英]Rails - Devise : Check if user can sign in

我使用devise处理Session。

登录前,我需要检查用户是否通过管理员验证。

我在模型“ is_validated”中添加了一个布尔字段。

在登录用户之前如何检查此字段?

您需要覆盖active_for_authentication? 设计功能。 基本上,您将额外条件放在该方法中,并且只有该方法为true时才能登录。

您可以在此处找到更多详细信息: https : //github.com/plataformatec/devise/wiki/操作方法-Customize-user-account-status-validation-when-logging-in

覆盖active_for_authentication? 模型中的方法

像这样 .......

class Your_model

  def active_for_authentication?
    super && is_validated?
  end

end

如果用户通过验证,则返回true。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM