2016-07-05 09:24:24 +00:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
Async = require('async')
|
|
|
|
|
2016-11-09 11:03:03 +00:00
|
|
|
UserSessionsRedis = require('../../../../app/js/Features/User/UserSessionsRedis')
|
|
|
|
|
|
|
|
# rclient = redis.createClient(Settings.redis.web)
|
|
|
|
rclient = UserSessionsRedis.client()
|
2016-07-05 09:24:24 +00:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getUserSessions: (user, callback=(err, sessionsSet)->) ->
|
2016-11-14 16:33:54 +00:00
|
|
|
rclient.smembers UserSessionsRedis.sessionSetKey(user), (err, result) ->
|
2016-09-06 14:55:34 +00:00
|
|
|
return callback(err, result)
|
2016-07-05 09:24:24 +00:00
|
|
|
|
|
|
|
clearUserSessions: (user, callback=(err)->) ->
|
2016-11-14 16:33:54 +00:00
|
|
|
sessionSetKey = UserSessionsRedis.sessionSetKey(user)
|
2016-07-05 09:24:24 +00:00
|
|
|
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
|
|
|
if err
|
|
|
|
return callback(err)
|
|
|
|
if sessionKeys.length == 0
|
|
|
|
return callback(null)
|
2016-11-09 11:03:03 +00:00
|
|
|
actions = sessionKeys.map (k) ->
|
|
|
|
(cb) ->
|
|
|
|
rclient.del k, (err) ->
|
|
|
|
cb(err)
|
|
|
|
Async.series(
|
|
|
|
actions, (err, results) ->
|
|
|
|
rclient.srem sessionSetKey, sessionKeys, (err) ->
|
|
|
|
if err
|
|
|
|
return callback(err)
|
|
|
|
callback(null)
|
|
|
|
)
|