-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix session retention after server restart; + see issue sailorproject…
- Loading branch information
Showing
3 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |