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,11 +16,14 @@ 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()
if err .sadd(sessionSetKey, value)
logger.err {err, user_id: user._id, sessionId}, "error while adding session key to UserSessions set" .expire(sessionSetKey, "#{Settings.cookieSessionLength}")
return callback(err) .exec (err, response) ->
callback() if err
logger.err {err, user_id: user._id, sessionId}, "error while adding session key to UserSessions set"
return callback(err)
callback()
onLogout: (user, sessionId, callback=(err)-> ) -> onLogout: (user, sessionId, callback=(err)-> ) ->
logger.log {user_id: user._id, sessionId}, "onLogout handler" logger.log {user_id: user._id, sessionId}, "onLogout handler"
@ -29,12 +32,24 @@ 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()
if err .srem(sessionSetKey, value)
logger.err {err, user_id: user._id, sessionId}, "error while removing session key from UserSessions set" .expire(sessionSetKey, "#{Settings.cookieSessionLength}")
return callback(err) .exec (err, response) ->
callback() if err
logger.err {err, user_id: user._id, sessionId}, "error while removing session key from UserSessions set"
return callback(err)
callback()
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
@ -114,7 +117,7 @@ app.use (req, res, next) ->
apiRouter.get "/status", (req, res)-> apiRouter.get "/status", (req, res)->
res.send("web sharelatex is alive") res.send("web sharelatex is alive")
profiler = require "v8-profiler" profiler = require "v8-profiler"
apiRouter.get "/profile", (req, res) -> apiRouter.get "/profile", (req, res) ->
time = parseInt(req.query.time || "1000") time = parseInt(req.query.time || "1000")