2012-10-23 19:12:00 +00:00
|
|
|
module SessionHelper
|
2012-10-23 20:25:42 +00:00
|
|
|
def self.default_collections(user)
|
2012-10-23 19:12:00 +00:00
|
|
|
|
|
|
|
# auto population collections, store all here
|
|
|
|
default_collection = {}
|
2014-08-02 21:53:10 +00:00
|
|
|
assets = {}
|
2012-10-23 19:12:00 +00:00
|
|
|
|
|
|
|
# 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
|
2014-08-02 21:53:10 +00:00
|
|
|
ExtraCollection.session( default_collection, assets, user )
|
2012-10-23 19:12:00 +00:00
|
|
|
end
|
|
|
|
|
2014-08-02 21:53:10 +00:00
|
|
|
return default_collection, assets
|
2012-10-23 19:12:00 +00:00
|
|
|
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
|
2012-10-23 19:12:00 +00:00
|
|
|
end
|