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 req.session.user = lightUser
UserSessionsManager.onLogin(user, req.sessionID, () ->) UserSessionsManager.trackSession(user, req.sessionID, () ->)
callback() callback()

View file

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

View file

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

View file

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

View file

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