diff --git a/src/models/api/requestModels.js b/src/models/api/requestModels.js index a12a283378..0e80590567 100644 --- a/src/models/api/requestModels.js +++ b/src/models/api/requestModels.js @@ -16,10 +16,10 @@ var TokenRequest = function (email, masterPasswordHash, token, device) { this.email = email; this.masterPasswordHash = masterPasswordHash; this.token = token; - this.provider = 'Authenticator'; + this.provider = 0; // authenticator this.device = null; if (device) { - this.device = new DeviceRequest(device); + this.device = device; } this.toIdentityToken = function () { @@ -62,9 +62,9 @@ var DeviceTokenRequest = function () { this.pushToken = null; }; -var DeviceRequest = function () { - this.type = null; - this.name = null; - this.identifier = null; +var DeviceRequest = function (appId, utilsService) { + this.type = utilsService.getDeviceType(); + this.name = utilsService.getBrowser(); + this.identifier = appId; this.pushToken = null; }; diff --git a/src/popup/app/services/authService.js b/src/popup/app/services/authService.js index db48620baf..29034311ca 100644 --- a/src/popup/app/services/authService.js +++ b/src/popup/app/services/authService.js @@ -2,7 +2,7 @@ .module('bit.services') .factory('authService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope, loginService, - folderService, settingsService, syncService) { + folderService, settingsService, syncService, appIdService, utilsService) { var _service = {}; _service.logIn = function (email, masterPassword, twoFactorToken) { @@ -10,30 +10,33 @@ var key = cryptoService.makeKey(masterPassword, email); var deferred = $q.defer(); cryptoService.hashPassword(masterPassword, key, function (hashedPassword) { - var request = new TokenRequest(email, hashedPassword, twoFactorToken); + appIdService.getAppId(function (appId) { + var deviceRequest = new DeviceRequest(appId, utilsService); + var request = new TokenRequest(email, hashedPassword, twoFactorToken, deviceRequest); - apiService.postIdentityToken(request, function (response) { - // success - if (!response || !response.accessToken) { - return; - } + apiService.postIdentityToken(request, function (response) { + // success + if (!response || !response.accessToken) { + return; + } - tokenService.setTokens(response.accessToken, response.refreshToken, function () { - cryptoService.setKey(key, function () { - cryptoService.setKeyHash(hashedPassword, function () { - userService.setUserIdAndEmail(tokenService.getUserId(), tokenService.getEmail(), function () { - chrome.runtime.sendMessage({ command: 'loggedIn' }); - deferred.resolve(false); + tokenService.setTokens(response.accessToken, response.refreshToken, function () { + cryptoService.setKey(key, function () { + cryptoService.setKeyHash(hashedPassword, function () { + userService.setUserIdAndEmail(tokenService.getUserId(), tokenService.getEmail(), function () { + chrome.runtime.sendMessage({ command: 'loggedIn' }); + deferred.resolve(false); + }); }); }); }); + }, function () { + // two factor required + deferred.resolve(true); + }, function (error) { + // error + deferred.reject(error); }); - }, function () { - // two factor required - deferred.resolve(true); - }, function (error) { - // error - deferred.reject(error); }); }); return deferred.promise; diff --git a/src/services/utilsService.js b/src/services/utilsService.js index 45f727c8d1..97b5b6748b 100644 --- a/src/services/utilsService.js +++ b/src/services/utilsService.js @@ -64,6 +64,23 @@ function initUtilsService() { return this.analyticsIdCache; } + UtilsService.prototype.getDeviceType = function () { + if (this.isChrome()) { + return 2; + } + else if (this.isFirefox()) { + return 3; + } + else if (this.isEdge()) { + return 5; + } + else if (this.isOpera()) { + return 4; + } + + return -1; + } + UtilsService.prototype.initListSectionItemListeners = function (doc, angular) { if (!doc) { throw 'doc parameter required';