Skip to content

Commit

Permalink
fix session retention after server restart; + see issue sailorproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
d9k committed Jun 18, 2018
1 parent 50de46b commit 5613d4b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
1 change: 1 addition & 0 deletions helpers/sailor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
M = {}

M.get_user = function()
local access = require 'access'
local session = require 'sailor.session'

local user = nil
Expand Down
5 changes: 2 additions & 3 deletions override_modules/override_map.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
local sailor_page_override = require 'override_modules.sailor_page'

package.loaded['sailor.page'] = sailor_page_override
package.loaded['sailor.page'] = require 'override_modules.sailor_page'
package.loaded['sailor.session'] = require 'override_modules.sailor_session'
96 changes: 96 additions & 0 deletions override_modules/sailor_session.lua
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
-- 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

0 comments on commit 5613d4b

Please sign in to comment.