0
我想根據具體情況禁用/啓用設計可鎖定模塊。例如,僅對非管理員用戶啓用可鎖定模塊。可以根據條件啓用/禁用設計可鎖定模塊
Confirmable
模塊中有一種方法,confirmation_required?
如果需要確認,可以覆蓋。
Lockable
模塊確實有類似的方法?任何幫助,將不勝感激
感謝
我想根據具體情況禁用/啓用設計可鎖定模塊。例如,僅對非管理員用戶啓用可鎖定模塊。可以根據條件啓用/禁用設計可鎖定模塊
Confirmable
模塊中有一種方法,confirmation_required?
如果需要確認,可以覆蓋。
Lockable
模塊確實有類似的方法?任何幫助,將不勝感激
感謝
把這個在你的用戶模型:
def active_for_authentication?
super && (admin? || !access_locked?)
end
def valid_for_authentication?
return super unless persisted? && lock_strategy_enabled?(:failed_attempts)
# Unlock the user if the lock is expired, no matter
# if the user can login or not (wrong password, etc)
unlock_access! if lock_expired?
if super && (admin? || !access_locked?)
true
else
self.failed_attempts ||= 0
self.failed_attempts += 1
if attempts_exceeded?
lock_access! unless access_locked?
else
save(validate: false)
end
false
end
end
謝謝您的回答,但它覆蓋2個色器件這些方法幾乎沒有什麼可怕的,特別是覆蓋'valid_for_authentication'方法。 – geekdev