2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
2020-12-15 05:23:54 -05:00
|
|
|
node/handle-callback-err,
|
2019-05-29 05:21:06 -04:00
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2019-05-29 05:21:06 -04:00
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const Async = require('async')
|
|
|
|
|
|
|
|
const UserSessionsRedis = require('../../../../app/src/Features/User/UserSessionsRedis')
|
|
|
|
|
|
|
|
// rclient = redis.createClient(Settings.redis.web)
|
|
|
|
const rclient = UserSessionsRedis.client()
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getUserSessions(user, callback) {
|
|
|
|
if (callback == null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
callback = function (err, sessionsSet) {}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
return rclient.smembers(
|
|
|
|
UserSessionsRedis.sessionSetKey(user),
|
|
|
|
(err, result) => callback(err, result)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
clearUserSessions(user, callback) {
|
|
|
|
if (callback == null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
callback = function (err) {}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
const sessionSetKey = UserSessionsRedis.sessionSetKey(user)
|
2019-08-07 10:04:04 -04:00
|
|
|
return rclient.smembers(sessionSetKey, (err, sessionKeys) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
if (sessionKeys.length === 0) {
|
|
|
|
return callback(null)
|
|
|
|
}
|
|
|
|
const actions = sessionKeys.map(k => cb => rclient.del(k, err => cb(err)))
|
|
|
|
return Async.series(actions, (err, results) =>
|
2019-08-07 10:04:04 -04:00
|
|
|
rclient.srem(sessionSetKey, sessionKeys, err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
return callback(null)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|