我想根据具体情况为用户禁用/启用设计可锁定模块。例如,仅为非管理员用户启用可锁定模块。
Confirmable
模块confirmation_required?
中有一个方法,如果需要确认,可以覆盖。
Lockable
模块确实有类似的方法吗?任何帮助将不胜感激
谢谢
答案 0 :(得分:0)
把它放在你的用户模型中:
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
答案 1 :(得分:0)
您可以将以下方法放在user.rb文件中
def lock_strategy_enabled?(strategy)
return false if self.admin?
true
end