mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor: add ?
suffix to truth tests.
This commit is contained in:
parent
21eb104928
commit
9e35bdcaea
3 changed files with 15 additions and 15 deletions
|
@ -122,7 +122,7 @@ module.exports = UserController =
|
||||||
AuthenticationManager.setUserPassword user._id, newPassword1, (error) ->
|
AuthenticationManager.setUserPassword user._id, newPassword1, (error) ->
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
UserSessionsManager.revokeAllUserSessions user, [req.sessionID], (err) ->
|
UserSessionsManager.revokeAllUserSessions user, [req.sessionID], (err) ->
|
||||||
return next(err) if err
|
return next(err) if err?
|
||||||
res.send
|
res.send
|
||||||
message:
|
message:
|
||||||
type:'success'
|
type:'success'
|
||||||
|
|
|
@ -16,10 +16,10 @@ module.exports = UserSessionsManager =
|
||||||
return "sess:#{sessionId}"
|
return "sess:#{sessionId}"
|
||||||
|
|
||||||
trackSession: (user, sessionId, callback=(err)-> ) ->
|
trackSession: (user, sessionId, callback=(err)-> ) ->
|
||||||
if !user
|
if !user?
|
||||||
logger.log {sessionId}, "no user to track, returning"
|
logger.log {sessionId}, "no user to track, returning"
|
||||||
return callback(null)
|
return callback(null)
|
||||||
if !sessionId
|
if !sessionId?
|
||||||
logger.log {user_id: user._id}, "no sessionId to track, returning"
|
logger.log {user_id: user._id}, "no sessionId to track, returning"
|
||||||
return callback(null)
|
return callback(null)
|
||||||
logger.log {user_id: user._id, sessionId}, "onLogin handler"
|
logger.log {user_id: user._id, sessionId}, "onLogin handler"
|
||||||
|
@ -29,17 +29,17 @@ module.exports = UserSessionsManager =
|
||||||
.sadd(sessionSetKey, value)
|
.sadd(sessionSetKey, value)
|
||||||
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
|
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
|
||||||
.exec (err, response) ->
|
.exec (err, response) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id, sessionSetKey}, "error while adding session key to UserSessions set"
|
logger.err {err, user_id: user._id, sessionSetKey}, "error while adding session key to UserSessions set"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
UserSessionsManager._checkSessions(user, () ->)
|
UserSessionsManager._checkSessions(user, () ->)
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
untrackSession: (user, sessionId, callback=(err)-> ) ->
|
untrackSession: (user, sessionId, callback=(err)-> ) ->
|
||||||
if !user
|
if !user?
|
||||||
logger.log {sessionId}, "no user to untrack, returning"
|
logger.log {sessionId}, "no user to untrack, returning"
|
||||||
return callback(null)
|
return callback(null)
|
||||||
if !sessionId
|
if !sessionId?
|
||||||
logger.log {user_id: user._id}, "no sessionId to untrack, returning"
|
logger.log {user_id: user._id}, "no sessionId to untrack, returning"
|
||||||
return callback(null)
|
return callback(null)
|
||||||
logger.log {user_id: user._id, sessionId}, "onLogout handler"
|
logger.log {user_id: user._id, sessionId}, "onLogout handler"
|
||||||
|
@ -52,7 +52,7 @@ module.exports = UserSessionsManager =
|
||||||
.srem(sessionSetKey, value)
|
.srem(sessionSetKey, value)
|
||||||
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
|
.expire(sessionSetKey, "#{Settings.cookieSessionLength}")
|
||||||
.exec (err, response) ->
|
.exec (err, response) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id, sessionSetKey}, "error while removing session key from UserSessions set"
|
logger.err {err, user_id: user._id, sessionSetKey}, "error while removing session key from UserSessions set"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
UserSessionsManager._checkSessions(user, () ->)
|
UserSessionsManager._checkSessions(user, () ->)
|
||||||
|
@ -68,7 +68,7 @@ module.exports = UserSessionsManager =
|
||||||
logger.log {user_id: user._id}, "revoking all existing sessions for user"
|
logger.log {user_id: user._id}, "revoking all existing sessions for user"
|
||||||
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
||||||
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set"
|
logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
keysToDelete = _.filter(sessionKeys, (k) -> k not in retain)
|
keysToDelete = _.filter(sessionKeys, (k) -> k not in retain)
|
||||||
|
@ -80,7 +80,7 @@ module.exports = UserSessionsManager =
|
||||||
.del(keysToDelete)
|
.del(keysToDelete)
|
||||||
.srem(sessionSetKey, keysToDelete)
|
.srem(sessionSetKey, keysToDelete)
|
||||||
.exec (err, result) ->
|
.exec (err, result) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id, sessionSetKey}, "error revoking all sessions for user"
|
logger.err {err, user_id: user._id, sessionSetKey}, "error revoking all sessions for user"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
callback(null)
|
callback(null)
|
||||||
|
@ -91,7 +91,7 @@ module.exports = UserSessionsManager =
|
||||||
return callback(null)
|
return callback(null)
|
||||||
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
||||||
rclient.expire sessionSetKey, "#{Settings.cookieSessionLength}", (err, response) ->
|
rclient.expire sessionSetKey, "#{Settings.cookieSessionLength}", (err, response) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id}, "error while updating ttl on UserSessions set"
|
logger.err {err, user_id: user._id}, "error while updating ttl on UserSessions set"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
callback(null)
|
callback(null)
|
||||||
|
@ -103,7 +103,7 @@ module.exports = UserSessionsManager =
|
||||||
logger.log {user_id: user._id}, "checking sessions for user"
|
logger.log {user_id: user._id}, "checking sessions for user"
|
||||||
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
sessionSetKey = UserSessionsManager._sessionSetKey(user)
|
||||||
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
rclient.smembers sessionSetKey, (err, sessionKeys) ->
|
||||||
if err
|
if err?
|
||||||
logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set"
|
logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
logger.log {user_id: user._id, count: sessionKeys.length}, "checking sessions for user"
|
logger.log {user_id: user._id, count: sessionKeys.length}, "checking sessions for user"
|
||||||
|
@ -112,12 +112,12 @@ module.exports = UserSessionsManager =
|
||||||
(key) ->
|
(key) ->
|
||||||
(next) ->
|
(next) ->
|
||||||
rclient.get key, (err, val) ->
|
rclient.get key, (err, val) ->
|
||||||
if err
|
if err?
|
||||||
return next(err)
|
return next(err)
|
||||||
if val == null
|
if !val?
|
||||||
logger.log {user_id: user._id, key}, ">> removing key from UserSessions set"
|
logger.log {user_id: user._id, key}, ">> removing key from UserSessions set"
|
||||||
rclient.srem sessionSetKey, key, (err, result) ->
|
rclient.srem sessionSetKey, key, (err, result) ->
|
||||||
if err
|
if err?
|
||||||
return next(err)
|
return next(err)
|
||||||
return next(null)
|
return next(null)
|
||||||
else
|
else
|
||||||
|
|
|
@ -90,7 +90,7 @@ 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
|
if req?.session?.user?
|
||||||
UserSessionsManager.touch(req.session.user, (err)->)
|
UserSessionsManager.touch(req.session.user, (err)->)
|
||||||
next()
|
next()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue