Module: Challah::UserAuthenticateable

Included in:
Userable
Defined in:
lib/challah/concerns/user/authenticateable.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(*args) ⇒ Object

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.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



26
27
28
# 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) ⇒ Object



22
23
24
# File 'lib/challah/concerns/user/authenticateable.rb', line 22

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

#failed_authentication!Object



30
31
32
# File 'lib/challah/concerns/user/authenticateable.rb', line 30

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

#successful_authentication!(ip_address = nil) ⇒ Object

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



36
37
38
39
40
41
# 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
  self.save
  self.increment!(:session_count, 1)
end