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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) column_name(attribute)



10
11
12
13
# File 'lib/sorcery/model/adapters/active_record.rb', line 10

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

- (Object) find_by_credentials(credentials)



15
16
17
18
# File 'lib/sorcery/model/adapters/active_record.rb', line 15

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

- (Object) find_by_sorcery_token(token_attr_name, token)



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

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

- (Object) get_current_users



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

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