簡體   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