2023-07-20 11:56:13 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
remove page_size/session_age from DB config
diff --git a/cogit/cfg.lua b/cogit/cfg.lua index 53f7358..6c4587a 100644 --- a/cogit/cfg.lua +++ b/cogit/cfg.lua @@ -3,12 +3,6 @@ local lud = require "ludweb" local hash = require "cogit.hash" local schema = [[ -CREATE TABLE IF NOT EXISTS Config ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - pg_size INTEGER NOT NULL, - ses_age INTEGER NOT NULL -); CREATE TABLE IF NOT EXISTS User ( id INTEGER PRIMARY KEY AUTOINCREMENT, nick TEXT NOT NULL UNIQUE, @@ -26,10 +20,6 @@ function CFG:add_defaults() local pass = hash.get_pass("admin password: ") local salt = hash.get_salt() local hash = hash.hash_pass(pass, salt) - self.db:execute[[ - INSERT INTO Config(id, name, pg_size, ses_age) VALUES - (1, "default", 20, 72*60*60); - ]] self.db:execute([[ INSERT INTO User(id, nick, name, salt, hash, is_admin) VALUES (1, "admin", "Admin", ?, ?, 1); @@ -39,23 +29,12 @@ end function CFG:init() self.db:execute_many(schema) - local config = self.db:execute("SELECT * FROM Config;")[1] - if config == nil then - self.cid = self:add_defaults() - else - self.cid = config.id + local admin = self:get_user("admin") + if admin == nil then + self:add_defaults() end end -function CFG:set_cid(cid) self.cid = cid end - -function CFG:get_config(col) - return self.db:execute("SELECT * FROM Config WHERE id = ?;", self.cid)[1][col] -end - -function CFG:pg_size() return self:get_config("pg_size") end -function CFG:ses_age() return self:get_config("ses_age") end - function CFG:get_user(nick) return self.db:execute("SELECT * FROM User WHERE nick = ?;", nick)[1] end diff --git a/cogit/cogit.lua b/cogit/cogit.lua index 0be9f1e..705ab65 100644 --- a/cogit/cogit.lua +++ b/cogit/cogit.lua @@ -112,7 +112,7 @@ end function Cogit:routes() local title = self.title - local limit = self.cfg:pg_size() + local limit = self.limit return { {"GET", "/?", function (req) @@ -154,7 +154,7 @@ function Cogit:routes() local session_id = lud.crypt.b64_enc(lud.crypt.uuid4()) self.sessions[session_id] = uname self:log(LOG_INFO, "logged in as "..uname) - local age = self.cfg:ses_age() + local age = self.session_age local cookie = {key="sid", val=session_id, path="/", age=age} return "/", 303, "See Other", {cookie} else @@ -272,6 +272,8 @@ local function new_cogit(path, port, title, log_level) port=tonumber(port) or 8080, title=title or "cogit", log_level=log_levels[log_level or "INFO"], + limit=20, + session_age=3*24*60*60, sessions={}, initialized=false, }