trabajo-afectivo/lib/session_helper.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

module SessionHelper
2012-10-23 20:25:42 +00:00
def self.default_collections(user)
# auto population collections, store all here
default_collection = {}
assets = {}
# load collections to deliver from external files
dir = File.expand_path('../../', __FILE__)
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
for file in files
load file
ExtraCollection.session( default_collection, assets, user )
end
return default_collection, assets
end
2013-12-08 16:01:54 +00:00
def self.cleanup_expired
# web sessions
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
# http basic auth calls
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
end
def self.get(id)
ActiveRecord::SessionStore::Session.where( :id => id ).first
end
def self.list(limit = 10000)
ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
end
def self.destroy(id)
session = ActiveRecord::SessionStore::Session.where( :id => id ).first
return if !session
session.destroy
end
end