module Challah::UserAuthenticateable

Public Instance Methods

authenticate(*args) click to toggle source

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.

# File lib/challah/concerns/user/authenticateable.rb, line 6
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
authenticate_with_api_key(api_key) click to toggle source
# File lib/challah/concerns/user/authenticateable.rb, line 26
def authenticate_with_api_key(api_key)
  authenticate(:api_key, api_key)
end
authenticate_with_password(plain_password) click to toggle source
# File lib/challah/concerns/user/authenticateable.rb, line 22
def authenticate_with_password(plain_password)
  authenticate(:password, plain_password)
end
failed_authentication!() click to toggle source
# File lib/challah/concerns/user/authenticateable.rb, line 30
def failed_authentication!
  self.increment!(:failed_auth_count)
end
successful_authentication!(ip_address = nil) click to toggle source

Called when a Session validation is successful, and this user has been authenticated.

# File lib/challah/concerns/user/authenticateable.rb, line 36
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