mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
promise conversions
This commit is contained in:
parent
1b66b255f3
commit
0fdee0f13b
@ -33,7 +33,7 @@ var bg_isBackground = true,
|
|||||||
bg_constantsService = new ConstantsService(bg_i18nService);
|
bg_constantsService = new ConstantsService(bg_i18nService);
|
||||||
bg_cryptoService = new CryptoService(bg_constantsService);
|
bg_cryptoService = new CryptoService(bg_constantsService);
|
||||||
bg_tokenService = new TokenService(bg_utilsService);
|
bg_tokenService = new TokenService(bg_utilsService);
|
||||||
bg_appIdService = new AppIdService();
|
bg_appIdService = new AppIdService(bg_utilsService);
|
||||||
bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
|
bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
|
||||||
bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
|
bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
|
||||||
bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);
|
bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);
|
||||||
|
@ -7,12 +7,15 @@
|
|||||||
|
|
||||||
_service.logIn = function (email, masterPassword, twoFactorProvider, twoFactorToken, remember) {
|
_service.logIn = function (email, masterPassword, twoFactorProvider, twoFactorToken, remember) {
|
||||||
email = email.toLowerCase();
|
email = email.toLowerCase();
|
||||||
var key = cryptoService.makeKey(masterPassword, email);
|
var key = cryptoService.makeKey(masterPassword, email),
|
||||||
var deferred = $q.defer();
|
deferred = $q.defer(),
|
||||||
|
deviceRequest = null;
|
||||||
|
|
||||||
|
appIdService.getAppId().then(function (appId) {
|
||||||
|
deviceRequest = new DeviceRequest(appId, utilsService);
|
||||||
|
return tokenService.getTwoFactorToken(email);
|
||||||
|
}).then(function (twoFactorRememberedToken) {
|
||||||
cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
|
cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
|
||||||
appIdService.getAppId(function (appId) {
|
|
||||||
tokenService.getTwoFactorToken(email, function (twoFactorRememberedToken) {
|
|
||||||
var deviceRequest = new DeviceRequest(appId, utilsService);
|
|
||||||
var request;
|
var request;
|
||||||
|
|
||||||
if (twoFactorToken && typeof (twoFactorProvider) !== 'undefined' && twoFactorProvider !== null) {
|
if (twoFactorToken && typeof (twoFactorProvider) !== 'undefined' && twoFactorProvider !== null) {
|
||||||
@ -67,7 +70,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
return encodeURIComponent(pagePath);
|
return encodeURIComponent(pagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bgPage.bg_appIdService.getAnonymousAppId(function (gaAnonAppId) {
|
bgPage.bg_appIdService.getAnonymousAppId().then(function (gaAnonAppId) {
|
||||||
gaFunc = function (action, param1, param2, param3, param4) {
|
gaFunc = function (action, param1, param2, param3, param4) {
|
||||||
if (action !== 'send' || !param1) {
|
if (action !== 'send' || !param1) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,35 +1,27 @@
|
|||||||
function AppIdService() {
|
function AppIdService(utilsService) {
|
||||||
|
this.utilsService = utilsService;
|
||||||
|
|
||||||
initAppIdService();
|
initAppIdService();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initAppIdService() {
|
function initAppIdService() {
|
||||||
AppIdService.prototype.getAppId = function (callback) {
|
AppIdService.prototype.getAppId = function () {
|
||||||
if (!callback || typeof callback !== 'function') {
|
return makeAndGetAppId('appId', this);
|
||||||
throw 'callback function required';
|
|
||||||
}
|
|
||||||
|
|
||||||
makeAndGetAppId('appId', callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AppIdService.prototype.getAnonymousAppId = function (callback) {
|
AppIdService.prototype.getAnonymousAppId = function () {
|
||||||
if (!callback || typeof callback !== 'function') {
|
return makeAndGetAppId('anonymousAppId', this);
|
||||||
throw 'callback function required';
|
|
||||||
}
|
|
||||||
|
|
||||||
makeAndGetAppId('anonymousAppId', callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function makeAndGetAppId(key, callback) {
|
function makeAndGetAppId(key, self) {
|
||||||
chrome.storage.local.get(key, function (obj) {
|
return self.utilsService.getObjFromStorage(key).then(function (obj) {
|
||||||
if (obj && obj[key]) {
|
if (obj) {
|
||||||
callback(obj[key]);
|
return obj;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var setObj = {};
|
var guid = newGuid();
|
||||||
setObj[key] = newGuid();
|
return self.utilsService.saveObjToStorage(key, guid).then(function () {
|
||||||
chrome.storage.local.set(setObj, function () {
|
return guid;
|
||||||
callback(setObj[key]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
function TokenService(utilsService) {
|
function TokenService(utilsService) {
|
||||||
this.utilsService = utilsService;
|
this.utilsService = utilsService;
|
||||||
|
|
||||||
initTokenService();
|
initTokenService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +98,9 @@ function initTokenService() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TokenService.prototype.getTwoFactorToken = function (email, callback) {
|
TokenService.prototype.getTwoFactorToken = function (email) {
|
||||||
if (!callback || typeof callback !== 'function') {
|
return this.utilsService.getObjFromStorage('twoFactorToken_' + email).then(function (token) {
|
||||||
throw 'callback function required';
|
return token;
|
||||||
}
|
|
||||||
|
|
||||||
var prop = 'twoFactorToken_' + email;
|
|
||||||
|
|
||||||
chrome.storage.local.get(prop, function (obj) {
|
|
||||||
if (obj && obj[prop]) {
|
|
||||||
callback(obj[prop]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return callback(null);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user