2016-07-05 05:24:24 -04:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
redis = require('redis-sharelatex')
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
Async = require('async')
|
|
|
|
|
2016-11-09 06:03:03 -05:00
|
|
|
UserSessionsRedis = require('../../../../app/js/Features/User/UserSessionsRedis')
|
|
|
|
|
|
|
|
# rclient = redis.createClient(Settings.redis.web)
|
|
|
|
rclient = UserSessionsRedis.client()
|
2016-07-05 05:24:24 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getUserSessions: (user, callback=(err, sessionsSet)->) ->
|
2016-11-14 11:33:54 -05:00
|
|
|
rclient.smembers UserSessionsRedis.sessionSetKey(user), (err, result) ->
|
2016-09-06 10:55:34 -04:00
|
|
|
return callback(err, result)
|
2016-07-05 05:24:24 -04:00
|
|
|
|
|
|
|
clearUserSessions: (user, callback=(err)->) ->
|
2016-11-14 11:33:54 -05:00
|
|
|
sessionSetKey = UserSessionsRedis.sessionSetKey(user)
|
2016-07-05 05:24:24 -04:00
|
|
|
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
|
|
|
if err
|
|
|
|
return callback(err)
|
|
|
|
if sessionKeys.length == 0
|
|
|
|
return callback(null)
|
2016-11-09 06:03:03 -05: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)
|
|
|
|
)
|