Sha256: b09a85e0293d59ba7f4867d5adbb47b3943f65afc122181e4f81201fdf0dc71e

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

module Devise

  module Models

    # Handles blocking a user access after a certain number of attempts.
    # Requires proper configuration of the Devise::Models::Lockable module.
    #
    module AuthyLockable

      extend ActiveSupport::Concern

      # Public: Determine if this is a lockable resource, via Devise::Models::Lockable.
      # Returns true
      # Raises an error if the Devise::Models::Lockable module is not configured.
      def lockable?
        raise 'Devise lockable extension required' unless respond_to? :lock_access!
        Devise.lock_strategy == :failed_attempts
      end

      # Public: Handle a failed 2FA attempt. If the resource is lockable via
      # Devise::Models::Lockable module then enforce that setting.
      #
      # Returns true if the user is locked out.
      def invalid_authy_attempt!
        return false unless lockable?

        self.failed_attempts ||= 0
        self.failed_attempts += 1

        if attempts_exceeded?
          lock_access! unless access_locked?
          true
        else
          save validate: false
          false
        end
      end

    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
devise-authy-2.3.1 lib/devise-authy/models/authy_lockable.rb
devise-authy-2.3.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-2.2.1 lib/devise-authy/models/authy_lockable.rb
devise-authy-2.2.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-2.1.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-2.0.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.11.1 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.11.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.10.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.9.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.8.3 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.8.2 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.8.1 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.8.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.7.0 lib/devise-authy/models/authy_lockable.rb
devise-authy-1.6.0 lib/devise-authy/models/authy_lockable.rb