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