From ed19454ecaecee663534159e6504190e1f09cf33 Mon Sep 17 00:00:00 2001 From: Dominic Lennon Date: Wed, 11 Jan 2017 10:51:41 +0000 Subject: [PATCH] Adding more specific timing for session timings --- src/database/mongo.js | 10 +++++++--- src/database/redis.js | 20 ++++++++++++-------- src/views/admin/settings/user.tpl | 28 ++++++++++++++++++++++------ src/webserver.js | 14 ++++++++++---- 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 47f7a0596e..9e1c3a5a8f 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -129,11 +129,15 @@ var rdb = require('./redis'); rdb.client = rdb.connect(); - var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14); + var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 0); + var ttlHours = 1000 * 60 * 60 * (parseInt(meta.config.loginHours, 10) || 0); + var ttlMinutes = 1000 * 60 * (parseInt(meta.config.loginMinutes, 10) || 0); + var ttlSeconds = 1000 * (parseInt(meta.config.loginSeconds, 10) || 0); + var ttlTotal = (ttlDays + ttlHours + ttlMinutes + ttlSeconds) || 1209600000; // Default to 14 days module.sessionStore = new sessionStore({ client: rdb.client, - ttl: ttlDays + ttl: ttlTotal }); } else if (nconf.get('mongo')) { sessionStore = require('connect-mongo')(session); @@ -141,7 +145,7 @@ db: db }); } - + callback(); }; diff --git a/src/database/redis.js b/src/database/redis.js index 153d2e3058..7d89054b26 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -59,14 +59,18 @@ }; module.initSessionStore = function (callback) { - var meta = require('../meta'); - connectRedis = require('connect-redis')(session); - - var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14); - - module.sessionStore = new connectRedis({ - client: redisClient, - ttl: ttlDays + var meta = require('../meta'); + var sessionStore = require('connect-redis')(session); + + var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 0); + var ttlHours = 1000 * 60 * 60 * (parseInt(meta.config.loginHours, 10) || 0); + var ttlMinutes = 1000 * 60 * (parseInt(meta.config.loginMinutes, 10) || 0); + var ttlSeconds = 1000 * (parseInt(meta.config.loginSeconds, 10) || 0); + var ttlTotal = (ttlDays + ttlHours + ttlMinutes + ttlSeconds) || 1209600000; // Default to 14 days + + module.sessionStore = new sessionStore({ + client: module.client, + ttl: ttlTotal }); if (typeof callback === 'function') { diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index b10ed37da9..440b34edbb 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -20,7 +20,8 @@
- +
@@ -103,10 +104,6 @@ -
- - -
@@ -115,6 +112,25 @@
+
+
Session time +
+
+
+
+ + + + + + + + +
+
+
+
+
[[admin/settings/user:registration]]
@@ -259,4 +275,4 @@
- + \ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index fec42974c6..686451aef7 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -52,7 +52,7 @@ server.on('error', function (err) { }); module.exports.listen = function (callback) { - callback = callback || function () {}; + callback = callback || function () { }; emailer.registerApp(app); setupExpressApp(app); @@ -139,7 +139,7 @@ function setupExpressApp(app) { app.use(relativePath + '/apple-touch-icon', middleware.routeTouchIcon); - app.use(bodyParser.urlencoded({extended: true})); + app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(cookieParser()); app.use(useragent.express()); @@ -170,8 +170,14 @@ function setupFavicon(app) { } function setupCookie() { + var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 0); + var ttlHours = 1000 * 60 * 60 * (parseInt(meta.config.loginHours, 10) || 0); + var ttlMinutes = 1000 * 60 * (parseInt(meta.config.loginMinutes, 10) || 0); + var ttlSeconds = 1000 * (parseInt(meta.config.loginSeconds, 10) || 0); + var ttlTotal = (ttlDays + ttlHours + ttlMinutes + ttlSeconds) || 1209600000; // Default to 14 days + var cookie = { - maxAge: 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14) + maxAge: ttlTotal }; if (nconf.get('cookieDomain') || meta.config.cookieDomain) { @@ -191,7 +197,7 @@ function setupCookie() { } function listen(callback) { - callback = callback || function () {}; + callback = callback || function () { }; var port = parseInt(nconf.get('port'), 10); var isSocket = isNaN(port); var socketPath = isSocket ? nconf.get('port') : '';