2016-06-08 47 views

回答

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 

距離文檔網站: http://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Lockable#active_for_authentication%3F-instance_method

+0

謝謝您的回答,但它覆蓋2個色器件這些方法幾乎沒有什麼可怕的,特別是覆蓋'valid_for_authentication'方法。 – geekdev

相關問題