diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-12-07 13:04:41 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-12-07 13:04:41 +0100 |
commit | 5effbf0ab6b3f8522dbdd1d909b3da148480053b (patch) | |
tree | 19e761a39eb11c8d25f3a3465d232d2fa8f6422b /server.js | |
parent | de3183e620f9a60d82456303880173a27ca2ef21 (diff) | |
download | server-5effbf0ab6b3f8522dbdd1d909b3da148480053b.tar.gz |
Put login session table in main database.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -44,15 +44,11 @@ if (process.env.MAIL_HOST && process.env.MAIL_PORT) { * Login session management. */ -const login_db = new sqlite3(process.env.LOGIN || "./login"); -login_db.pragma("journal_mode = WAL"); -login_db.pragma("synchronous = OFF"); -login_db.exec("create table if not exists sessions (sid integer primary key, user_id integer, expires real)"); -login_db.exec("delete from sessions where expires < julianday()"); -const login_sql_select = login_db.prepare("select user_id from sessions where sid = ? and expires > julianday()").pluck(); -const login_sql_insert = login_db.prepare("insert into sessions values (abs(random()) % (1<<48), ?, julianday() + 28) returning sid").pluck(); -const login_sql_delete = login_db.prepare("delete from sessions where sid = ?"); -const login_sql_touch = login_db.prepare("update sessions set expires = julianday() + 28 where sid=? and expires < julianday() + 27"); +db.exec("delete from logins where expires < julianday()"); +const login_sql_select = SQL("select user_id from logins where sid = ? and expires > julianday()").pluck(); +const login_sql_insert = SQL("insert into logins values (abs(random()) % (1<<48), ?, julianday() + 28) returning sid").pluck(); +const login_sql_delete = SQL("delete from logins where sid = ?"); +const login_sql_touch = SQL("update logins set expires = julianday() + 28 where sid = ? and expires < julianday() + 27"); function login_cookie(req) { let c = req.headers.cookie; |