您好,
我在顯示設計失敗訊息時遇到問題。無論我做什么,即使帳戶被鎖定,我也總是收到“無效”訊息。我的目標是在 5 次嘗試失敗后顯示“鎖定”訊息 10 分鐘。
gem 配置正確,因為帳戶被正確鎖定。我唯一的問題是訊息。
這是我來自 devise.rb 檔案的代碼,它與可鎖定模塊相關:
config.paranoid = false
config.lock_strategy = :failed_attempts
config.unlock_keys = [:time]
config.unlock_strategy = :time
config.maximum_attempts = 5
config.unlock_in = 10.minutes
config.last_attempt_warning = true
我在 stackoverflow 上發現了其他主題(例如,某些設計訊息未顯示,設計:可鎖定 - last_attempt_warning 未顯示),人們說這是因為偏執模式,這就是我禁用它的原因,但它仍然沒有解決我的問題。無論我在 Devise 組態檔中輸入什么(last_attempt_warning 也沒有顯示),Devise 似乎沒有顯示除“無效”之外的任何其他訊息。
這是與故障相關的 devise.en.yml 的一部分:
en:
devise:
failure:
already_authenticated: "You are already logged in."
deactivated: "Your account is no longer active. Please contact your administrator for access."
inactive: "Your account is not activated yet."
invalid: "Sorry, the email or password you entered is incorrect."
last_attempt: "You have one more attempt before your account will be locked."
locked: "Your account has been locked. Try to log in again in 5 minutes."
not_found_in_database: "Sorry, the email or password you entered is incorrect."
timeout: "Your session expired. Please log in again to continue."
unauthenticated: "You need to log in or sign up before continuing."
unconfirmed: "You have to confirm your account before continuing."
我試圖通過在 Sessions Controller 中創建一個方法來解決它:
before_action :check_failed_attempts, only: :create
def check_failed_attempts
flash.clear
email = params["educator"]["email"]
return unless email
user = Person.find_by(email: email)
return unless user
if user.access_locked?
flash[:alert] = I18n.t "devise.failure.locked"
end
end
但 devise 似乎覆寫了 flash[:alert] 并無論如何顯示無效訊息。
我花了幾個小時試圖修復它并且已經沒有想法了,所以我感謝任何幫助。
uj5u.com熱心網友回復:
你是不是停止在您的請求周期before_action,因此請求正在進行呼叫create這是壓倒一切的動作flash[:alert]。從檔案:
如果“之前”過濾器呈現或重定向,則操作將不會運行。如果有其他過濾器計劃在該過濾器之后運行,它們也會被取消。
def check_failed_attempts
flash.clear
email = params["educator"]["email"]
return unless email
user = Person.find_by(email: email)
return unless user
if user.access_locked?
flash[:alert] = I18n.t "devise.failure.locked"
redirect_to new_educator_session_path
end
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/314945.html
