Sha256: d14db4f92eedad3a419a5c21e6e56bad9f4a539e92334710beb4d67d75e7362d

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 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 if respond_to?(:last_session_ip=)
      self.save
      self.increment!(:session_count, 1)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
challah-1.6.1 lib/challah/concerns/user/authenticateable.rb