Module: Sorcery::Model::Adapters::ActiveRecord::ClassMethods

Defined in:
lib/sorcery/model/adapters/active_record.rb

Instance Method Summary collapse

Instance Method Details

#column_name(attribute) ⇒ Object



20
21
22
23
# File 'lib/sorcery/model/adapters/active_record.rb', line 20

def column_name(attribute)
  return "LOWER(#{attribute})" if (@sorcery_config.downcase_username_before_authenticating)
  return "#{attribute}"
end

#find_by_credentials(credentials) ⇒ Object



25
26
27
28
# File 'lib/sorcery/model/adapters/active_record.rb', line 25

def find_by_credentials(credentials)
   sql = @sorcery_config.username_attribute_names.map{|attribute| column_name(attribute) + " = :login"}
   where(sql.join(' OR '), :login => credentials[0]).first
end

#find_by_sorcery_token(token_attr_name, token) ⇒ Object



30
31
32
# File 'lib/sorcery/model/adapters/active_record.rb', line 30

def find_by_sorcery_token(token_attr_name, token)
  where("#{token_attr_name} = ?", token).first
end

#get_current_usersObject



34
35
36
37
38
39
# File 'lib/sorcery/model/adapters/active_record.rb', line 34

def get_current_users
  config = sorcery_config
  where("#{config.last_activity_at_attribute_name} IS NOT NULL") \
  .where("#{config.last_logout_at_attribute_name} IS NULL OR #{config.last_activity_at_attribute_name} > #{config.last_logout_at_attribute_name}") \
  .where("#{config.last_activity_at_attribute_name} > ? ", config.activity_timeout.seconds.ago.utc.to_s(:db))
end