Sha256: 4d7422bc302ae5c0ec1f2eeb257f33f0f1b471ab244aa1510e5d24ca713d3772

Contents?: true

Size: 1.18 KB

Versions: 23

Compression:

Stored size: 1.18 KB

Contents

module Challah
  module UserAuthenticateable
    # Generic authentication method. By default, this just checks to see if the password
    # given matches this user. You can also pass in the first parameter as the method
    # to use for a different type of authentication.
    def authenticate(*args)
      return false unless active?

      if args.length > 1
        method = args.shift

        if Challah.authenticators[method]
          return Challah.authenticators[method].match?(self, providers[method], *args)
        end

        false
      else
        self.authenticate(:password, args[0])
      end
    end

    def authenticate_with_password(plain_password)
      authenticate(:password, plain_password)
    end

    def authenticate_with_api_key(api_key)
      authenticate(:api_key, api_key)
    end

    def failed_authentication!
      self.increment!(:failed_auth_count)
    end

    # Called when a +Session+ validation is successful, and this user has
    # been authenticated.
    def successful_authentication!(ip_address = nil)
      self.last_session_at = Time.now
      self.last_session_ip = ip_address
      self.save
      self.increment!(:session_count, 1)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
challah-1.6.0 lib/challah/concerns/user/authenticateable.rb
challah-1.5.0 lib/challah/concerns/user/authenticateable.rb
challah-1.4.2 lib/challah/concerns/user/authenticateable.rb
challah-1.4.1 lib/challah/concerns/user/authenticateable.rb
challah-1.4.0 lib/challah/concerns/user/authenticateable.rb
challah-1.3.3 lib/challah/concerns/user/authenticateable.rb
challah-1.3.2 lib/challah/concerns/user/authenticateable.rb
challah-1.3.1 lib/challah/concerns/user/authenticateable.rb
challah-1.3.0 lib/challah/concerns/user/authenticateable.rb
challah-1.2.11 lib/challah/concerns/user/authenticateable.rb
challah-1.2.10 lib/challah/concerns/user/authenticateable.rb
challah-1.2.9 lib/challah/concerns/user/authenticateable.rb
challah-1.2.8 lib/challah/concerns/user/authenticateable.rb
challah-1.2.7 lib/challah/concerns/user/authenticateable.rb
challah-1.2.6 lib/challah/concerns/user/authenticateable.rb
challah-1.2.5 lib/challah/concerns/user/authenticateable.rb
challah-1.2.5.pre lib/challah/concerns/user/authenticateable.rb
challah-1.2.4 lib/challah/concerns/user/authenticateable.rb
challah-1.2.3 lib/challah/concerns/user/authenticateable.rb
challah-1.2.2 lib/challah/concerns/user/authenticateable.rb