mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:23:59 +00:00
Begin keeping record of user sessions in reds.
This commit is contained in:
parent
9e16f250f9
commit
db213c0621
3 changed files with 38 additions and 0 deletions
|
@ -9,6 +9,7 @@ Url = require("url")
|
|||
Settings = require "settings-sharelatex"
|
||||
basicAuth = require('basic-auth-connect')
|
||||
UserHandler = require("../User/UserHandler")
|
||||
UserSessionsManager = require("../User/UserSessionsManager")
|
||||
|
||||
module.exports = AuthenticationController =
|
||||
login: (req, res, next = (error) ->) ->
|
||||
|
@ -141,4 +142,6 @@ module.exports = AuthenticationController =
|
|||
req.session[key] = value
|
||||
|
||||
req.session.user = lightUser
|
||||
|
||||
UserSessionsManager.onLogin(user, req.sessionID, () ->)
|
||||
callback()
|
||||
|
|
|
@ -8,6 +8,7 @@ logger = require("logger-sharelatex")
|
|||
metrics = require("../../infrastructure/Metrics")
|
||||
Url = require("url")
|
||||
AuthenticationManager = require("../Authentication/AuthenticationManager")
|
||||
UserSessionsManager = require("./UserSessionsManager")
|
||||
UserUpdater = require("./UserUpdater")
|
||||
settings = require "settings-sharelatex"
|
||||
|
||||
|
@ -81,9 +82,12 @@ module.exports = UserController =
|
|||
logout : (req, res)->
|
||||
metrics.inc "user.logout"
|
||||
logger.log user: req?.session?.user, "logging out"
|
||||
sessionId = "#{req.sessionID}"
|
||||
user = req?.session?.user
|
||||
req.session.destroy (err)->
|
||||
if err
|
||||
logger.err err: err, 'error destorying session'
|
||||
UserSessionsManager.onLogout(user, sessionId)
|
||||
res.redirect '/login'
|
||||
|
||||
register : (req, res, next = (error) ->)->
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
Settings = require('settings-sharelatex')
|
||||
redis = require('redis-sharelatex')
|
||||
rclient = redis.createClient(Settings.redis.web)
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
module.exports = UserSessionsManager =
|
||||
|
||||
_sessionSetKey: (user) ->
|
||||
console.log ">>", user
|
||||
return "UserSessions:#{user._id}"
|
||||
|
||||
onLogin: (user, sessionId, callback=(err)-> ) ->
|
||||
logger.log {user_id: user._id, sessionId}, "onLogin handler"
|
||||
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
||||
rclient.sadd sessionSetKey, sessionId, (err, response) ->
|
||||
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)-> ) ->
|
||||
logger.log {user_id: user._id, sessionId}, "onLogout handler"
|
||||
if !user
|
||||
logger.log {sessionId}, "no user, for some reason"
|
||||
return callback()
|
||||
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
||||
rclient.srem sessionSetKey, sessionId, (err, response) ->
|
||||
if err
|
||||
logger.err {err, user_id: user._id, sessionId}, "error while removing session key from UserSessions set"
|
||||
return callback(err)
|
||||
callback()
|
Loading…
Reference in a new issue