diff --git a/helpers/sailor.lua b/helpers/sailor.lua index b4f0db7..531a7f6 100644 --- a/helpers/sailor.lua +++ b/helpers/sailor.lua @@ -3,6 +3,7 @@ M = {} M.get_user = function() + local access = require 'access' local session = require 'sailor.session' local user = nil diff --git a/override_modules/override_map.lua b/override_modules/override_map.lua index b981f95..706cff3 100644 --- a/override_modules/override_map.lua +++ b/override_modules/override_map.lua @@ -1,3 +1,2 @@ -local sailor_page_override = require 'override_modules.sailor_page' - -package.loaded['sailor.page'] = sailor_page_override \ No newline at end of file +package.loaded['sailor.page'] = require 'override_modules.sailor_page' +package.loaded['sailor.session'] = require 'override_modules.sailor_session' \ No newline at end of file diff --git a/override_modules/sailor_session.lua b/override_modules/sailor_session.lua new file mode 100644 index 0000000..163dac2 --- /dev/null +++ b/override_modules/sailor_session.lua @@ -0,0 +1,96 @@ +-------------------------------------------------------------------------------- +-- session.lua, v0.2.1: cgilua session abstraction +-- This file is a part of Sailor project +-- Copyright (c) 2014 Etiene Dalcol +-- License: MIT +-- http://sailorproject.org +-------------------------------------------------------------------------------- + +local sailor = require "sailor" +local utils = require "web_utils.utils" +local session = require "web_utils.session" +local cookie = require "sailor.cookie" + +local ID_NAME = "SAILORSESSID" + +session.id = nil + +local sailor_init_complete = false + +session.after_sailor_init = function() + if sailor_init_complete then + return + end + + local conf = require 'conf.conf' + + session.setsessiondir (sailor.path..'/runtime/tmp') + -- https://github.com/sailorproject/sailor/issues/164 temporary fix + + if conf.access_module and conf.access_module.grant_time then + session.setsessiontimeout(conf.access_module.grant_time) + end + sailor_init_complete = true +end + + + +function session.open (r) + session.after_sailor_init() + + if session.id then + return session.id + end + + local id = cookie.get(r,ID_NAME ) + if not id then + session.new(r) + else + session.data = session.load(id) + if session.data then + session.id = id + else + session.new(r) + end + end + + session.cleanup() + return id +end + +function session.destroy (r) + session.after_sailor_init() + + local id = session.id or cookie.get(r,ID_NAME ) + if id then + session.data = {} + session.delete (id) + end + session.id = nil + return true +end + +local new = session.new +function session.new(r) + session.after_sailor_init() + + session.id = new() + session.data = {} + cookie.set(r,ID_NAME,session.id) +end + +local save = session.save +function session.save(data) + session.after_sailor_init() + + save(session.id,data) + session.data = data + return true +end + +function session.is_active() + return session.id ~= nil +end + + +return session