Refactor method names in UserSessionsManager

This commit is contained in:
Shane Kilkelly 2016-07-01 15:33:59 +01:00
parent 6938f1d055
commit f1653d01b7
5 changed files with 51 additions and 50 deletions

View file

@ -143,5 +143,5 @@ module.exports = AuthenticationController =
req.session.user = lightUser
UserSessionsManager.onLogin(user, req.sessionID, () ->)
UserSessionsManager.trackSession(user, req.sessionID, () ->)
callback()

View file

@ -87,7 +87,7 @@ module.exports = UserController =
req.session.destroy (err)->
if err
logger.err err: err, 'error destorying session'
UserSessionsManager.onLogout(user, sessionId)
UserSessionsManager.untrackSession(user, sessionId)
res.redirect '/login'
register : (req, res, next = (error) ->)->
@ -121,7 +121,7 @@ module.exports = UserController =
logger.log user: user, "password changed"
AuthenticationManager.setUserPassword user._id, newPassword1, (error) ->
return next(error) if error?
UserSessionsManager.revokeAllSessions user, (err) ->
UserSessionsManager.revokeAllUserSessions user, (err) ->
return next(err) if err
res.send
message:

View file

@ -12,7 +12,7 @@ module.exports = UserSessionsManager =
_sessionKey: (sessionId) ->
return "sess:#{sessionId}"
onLogin: (user, sessionId, callback=(err)-> ) ->
trackSession: (user, sessionId, callback=(err)-> ) ->
logger.log {user_id: user._id, sessionId}, "onLogin handler"
sessionSetKey = UserSessionsManager._sessionSetKey(user)
value = UserSessionsManager._sessionKey sessionId
@ -25,7 +25,7 @@ module.exports = UserSessionsManager =
return callback(err)
callback()
onLogout: (user, sessionId, callback=(err)-> ) ->
untrackSession: (user, sessionId, callback=(err)-> ) ->
logger.log {user_id: user._id, sessionId}, "onLogout handler"
if !user
logger.log {sessionId}, "no user, for some reason"
@ -41,7 +41,7 @@ module.exports = UserSessionsManager =
return callback(err)
callback()
revokeAllSessions: (user, callback=(err)->) ->
revokeAllUserSessions: (user, callback=(err)->) ->
logger.log {user_id: user._id}, "revoking all existing sessions for user"
sessionSetKey = UserSessionsManager._sessionSetKey(user)
rclient.smembers sessionSetKey, (err, sessionKeys) ->

View file

@ -21,6 +21,10 @@ describe "AuthenticationController", ->
"../User/UserHandler": @UserHandler = {setupLoginData:sinon.stub()}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"settings-sharelatex": {}
"../User/UserSessionsManager": @UserSessionsManager =
trackSession: sinon.stub()
untrackSession: sinon.stub()
revokeAllUserSessions: sinon.stub().callsArgWith(1, null)
@user =
_id: ObjectId()
email: @email = "USER@example.com"
@ -383,4 +387,3 @@ describe "AuthenticationController", ->
it "should return the callback", ->
@callback.called.should.equal true

View file

@ -45,9 +45,9 @@ describe "UserController", ->
@UserHandler =
populateGroupLicenceInvite:sinon.stub().callsArgWith(1)
@UserSessionsManager =
onLogin: sinon.stub()
onLogout: sinon.stub()
revokeAllSessions: sinon.stub().callsArgWith(1, null)
trackSession: sinon.stub()
untrackSession: sinon.stub()
revokeAllUserSessions: sinon.stub().callsArgWith(1, null)
@UserController = SandboxedModule.require modulePath, requires:
"./UserLocator": @UserLocator
"./UserDeleter": @UserDeleter
@ -250,5 +250,3 @@ describe "UserController", ->
@AuthenticationManager.setUserPassword.calledWith(@user._id, "newpass").should.equal true
done()
@UserController.changePassword @req, @res