3 var env
= require('gitter-web-env');
6 var _
= require('lodash');
7 var emailAddressService
= require('gitter-web-email-addresses');
8 var useragentTagger
= require('./user-agent-tagger');
10 // Use this whenever a user logs in again
11 module
.exports
= function trackUserLogin(req
, user
, provider
) {
12 return emailAddressService(user
).then(function(email
) {
13 var properties
= useragentTagger(req
);
15 const emailList
= user
.emails
|| [];
16 emailList
.unshift(email
);
17 // We are sanitizing the data a bit here so the database
18 // doesn't store `null` and duplicate case different emails
19 const lowerCaseEmailList
= emailList
.filter(email
=> !!email
).map(email
=> email
.toLowerCase());
20 user
.emails
= _
.uniq(lowerCaseEmailList
);
23 Object
.assign({}, user
, {
24 // this is only set because stats.userUpdate requires it
30 // NOTE: other stats calls also pass in source and googleAnalyticsUniqueId
36 method
: provider
+ '_oauth',
37 username
: user
.username
43 // Persist the new emails