idendifyUser on login

This commit is contained in:
Henry Oswald 2017-03-22 15:50:49 +00:00
parent f910bb58de
commit ebdce6169e
3 changed files with 9 additions and 2 deletions

View file

@ -16,14 +16,15 @@ makeRequest = (opts, callback)->
module.exports =
idendifyUser: (user_id, old_user_id, callback)->
idendifyUser: (user_id, old_user_id, callback = (error)->)->
opts =
body:
old_user_id:old_user_id
json:true
method:"POST"
timeout:1000
url: "/user/#{user_id}/idendify"
url: "/user/#{user_id}/identify"
makeRequest opts, callback
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
if user_id+"" == settings.smokeTest?.userId+""

View file

@ -87,6 +87,7 @@ module.exports = AuthenticationController =
LoginRateLimiter.recordSuccessfulLogin(email)
AuthenticationController._recordSuccessfulLogin(user._id)
Analytics.recordEvent(user._id, "user-logged-in", {ip:req.ip})
Analytics.idendifyUser(user._id, req.sessionID)
logger.log email: email, user_id: user._id.toString(), "successful log in"
req.session.justLoggedIn = true
# capture the request ip for use when creating the session

View file

@ -254,6 +254,8 @@ describe "AuthenticationController", ->
@cb = sinon.stub()
@LoginRateLimiter.processLoginRequest.callsArgWith(1, null, true)
@AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, null, @user)
@req.sessionID = Math.random()
@AnalyticsManager.idendifyUser = sinon.stub()
@AuthenticationController.doPassportLogin(@req, @req.body.email, @req.body.password, @cb)
it "should attempt to authorise the user", ->
@ -261,6 +263,9 @@ describe "AuthenticationController", ->
.calledWith(email: @email.toLowerCase(), @password)
.should.equal true
it "should call idendifyUser", ->
@AnalyticsManager.idendifyUser.calledWith(@user._id, @req.sessionID).should.equal true
it "should setup the user data in the background", ->
@UserHandler.setupLoginData.calledWith(@user).should.equal true