set expiry on the user sessions set.

This commit is contained in:
Shane Kilkelly 2016-07-01 11:24:46 +01:00
parent ab26edb44b
commit d8ffa5b4b1
2 changed files with 29 additions and 11 deletions

View file

@ -16,7 +16,10 @@ module.exports = UserSessionsManager =
logger.log {user_id: user._id, sessionId}, "onLogin handler" logger.log {user_id: user._id, sessionId}, "onLogin handler"
sessionSetKey = UserSessionsManager._sessionSetKey(user) sessionSetKey = UserSessionsManager._sessionSetKey(user)
value = UserSessionsManager._sessionKey sessionId value = UserSessionsManager._sessionKey sessionId
rclient.sadd sessionSetKey, value, (err, response) -> rclient.multi()
.sadd(sessionSetKey, value)
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
.exec (err, response) ->
if err if err
logger.err {err, user_id: user._id, sessionId}, "error while adding session key to UserSessions set" logger.err {err, user_id: user._id, sessionId}, "error while adding session key to UserSessions set"
return callback(err) return callback(err)
@ -29,7 +32,10 @@ module.exports = UserSessionsManager =
return callback() return callback()
sessionSetKey = UserSessionsManager._sessionSetKey(user) sessionSetKey = UserSessionsManager._sessionSetKey(user)
value = UserSessionsManager._sessionKey sessionId value = UserSessionsManager._sessionKey sessionId
rclient.srem sessionSetKey, value, (err, response) -> rclient.multi()
.srem(sessionSetKey, value)
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
.exec (err, response) ->
if err if err
logger.err {err, user_id: user._id, sessionId}, "error while removing session key from UserSessions set" logger.err {err, user_id: user._id, sessionId}, "error while removing session key from UserSessions set"
return callback(err) return callback(err)
@ -38,3 +44,12 @@ module.exports = UserSessionsManager =
revokeAllSessions: (user, callback=(err)->) -> revokeAllSessions: (user, callback=(err)->) ->
logger.log {user_id: user._id}, "revoking all existing sessions for user" logger.log {user_id: user._id}, "revoking all existing sessions for user"
callback(null) callback(null)
touch: (user, callback=(err)->) ->
if !user
return callback(null)
sessionSetKey = UserSessionsManager._sessionSetKey(user)
rclient.expire sessionSetKey, "#{Settings.cookieSessionLength}", (err, response) ->
if err
logger.err {err, user_id: user._id}, "error while updating ttl on UserSessions set"
return callback(err)

View file

@ -31,6 +31,7 @@ translations = require("translations-sharelatex").setup(Settings.i18n)
Modules = require "./Modules" Modules = require "./Modules"
ErrorController = require "../Features/Errors/ErrorController" ErrorController = require "../Features/Errors/ErrorController"
UserSessionsManager = require "../Features/User/UserSessionsManager"
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger) metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger)
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger) metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger)
@ -89,6 +90,8 @@ webRouter.use translations.setLangBasedOnDomainMiddlewear
# Measure expiry from last request, not last login # Measure expiry from last request, not last login
webRouter.use (req, res, next) -> webRouter.use (req, res, next) ->
req.session.touch() req.session.touch()
if req?.session?.user
UserSessionsManager.touch(req.session.user, (err)->)
next() next()
webRouter.use ReferalConnect.use webRouter.use ReferalConnect.use