set session cookie with expiration date and secure flag

This commit is contained in:
Lera Elvoé 2025-05-27 18:57:20 +03:00
parent 90cacad449
commit 873a4c0c15
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc

View File

@ -1,4 +1,5 @@
local lapis = require("lapis")
local date = require("date")
local app = lapis.Application()
local constants = require("constants")
local babycode = require("lib.babycode")
@ -14,6 +15,13 @@ local util = require("util")
app:enable("etlua")
app.layout = require "views.base"
app.cookie_attributes = function (self, name, value)
if name == config.session_name then
local expires = date(true):adddays(30):fmt("${http}")
return "Expires="..expires.."; Path=/; HttpOnly; Secure"
end
end
local function inject_constants(req)
req.constants = constants
math.randomseed(os.time())