Class: Cassy::Authenticators::Devise

Inherits:
Base
  • Object
show all
Defined in:
lib/cassy/authenticators/devise.rb

Class Method Summary collapse

Methods inherited from Base

configure, extra_attributes, extra_attributes_to_extract, setup, #validate

Class Method Details

.find_user(credentials) ⇒ Object



5
6
7
8
9
# File 'lib/cassy/authenticators/devise.rb', line 5

def self.find_user(credentials)
  # Find the user with the given email
  method = "find_by_#{Cassy.config[:username_field] || 'email'}"
  User.send(method, credentials[:username])
end

.find_user_from_ticket(ticket) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/cassy/authenticators/devise.rb', line 11

def self.find_user_from_ticket(ticket)
  return if ticket.nil?
  key  = Cassy.config[:client_app_user_field] || Cassy.config[:username_field] || "email"
  method = "find_by_#{key}"
  username = Cassy.config[:concurrent_session_types] ? Cassy.config[:concurrent_session_types].each{ |cst| break ticket.username.rpartition("-#{cst}").first if ticket.username.match("-#{cst}") } : ticket.username
  User.send(method, username)
end

.validate(credentials) ⇒ Object



19
20
21
22
23
# File 'lib/cassy/authenticators/devise.rb', line 19

def self.validate(credentials)
  user = find_user(credentials)
  # Did we find a user, are they active? and is their password valid?
  user && user.active_for_authentication? && user.valid_password?(credentials[:password])
end