mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
convert methods to promises
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, utilsService, SweetAlert,
|
||||
@@ -85,7 +85,7 @@
|
||||
}
|
||||
|
||||
var key = cryptoService.makeKey(masterPassword, email);
|
||||
cryptoService.hashPassword(masterPassword, key, function (hash) {
|
||||
cryptoService.hashPassword(masterPassword, key).then(function (hash) {
|
||||
var request = new TwoFactorEmailRequest(email, hash);
|
||||
apiService.postTwoFactorEmail(request, function () {
|
||||
if (doToast) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller(
|
||||
@@ -46,7 +46,8 @@
|
||||
function registerPromise(key, masterPassword, email, hint) {
|
||||
var deferred = $q.defer();
|
||||
cryptoService.makeEncKey(key).then(function (encKey) {
|
||||
cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
|
||||
return cryptoService.hashPassword(masterPassword, key);
|
||||
}).then(function (hashedPassword) {
|
||||
var request = new RegisterRequest(email, hashedPassword, hint, encKey.encryptedString);
|
||||
apiService.postRegister(request,
|
||||
function () {
|
||||
@@ -56,7 +57,6 @@
|
||||
deferred.reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.lock')
|
||||
|
||||
.controller('lockController', function ($scope, $state, $analytics, i18nService, cryptoService, toastr,
|
||||
@@ -26,8 +26,9 @@
|
||||
$scope.submit = function () {
|
||||
userService.getEmail(function (email) {
|
||||
var key = cryptoService.makeKey($scope.masterPassword, email);
|
||||
cryptoService.hashPassword($scope.masterPassword, key, function (keyHash) {
|
||||
cryptoService.getKeyHash(function (storedKeyHash) {
|
||||
cryptoService.hashPassword($scope.masterPassword, key).then(function (keyHash) {
|
||||
return cryptoService.getKeyHash();
|
||||
}).then(function (storedKeyHash) {
|
||||
if (storedKeyHash && keyHash && storedKeyHash === keyHash) {
|
||||
cryptoService.setKey(key).then(function () {
|
||||
chrome.runtime.sendMessage({ command: 'unlocked' });
|
||||
@@ -39,6 +40,5 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('authService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope,
|
||||
@@ -15,7 +15,8 @@
|
||||
deviceRequest = new DeviceRequest(appId, utilsService);
|
||||
return tokenService.getTwoFactorToken(email);
|
||||
}).then(function (twoFactorRememberedToken) {
|
||||
cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
|
||||
return cryptoService.hashPassword(masterPassword, key);
|
||||
}).then(function (hashedPassword) {
|
||||
var request;
|
||||
|
||||
if (twoFactorToken && typeof (twoFactorProvider) !== 'undefined' && twoFactorProvider !== null) {
|
||||
@@ -42,7 +43,8 @@
|
||||
|
||||
tokenService.setTokens(response.accessToken, response.refreshToken, function () {
|
||||
cryptoService.setKey(key).then(function () {
|
||||
cryptoService.setKeyHash(hashedPassword, function () {
|
||||
return cryptoService.setKeyHash(hashedPassword);
|
||||
}).then(function () {
|
||||
userService.setUserIdAndEmail(tokenService.getUserId(), tokenService.getEmail(),
|
||||
function () {
|
||||
cryptoService.setEncKey(response.key).then(function () {
|
||||
@@ -57,7 +59,6 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, function (providers) {
|
||||
// two factor required
|
||||
deferred.resolve({
|
||||
@@ -69,7 +70,6 @@
|
||||
deferred.reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.settings')
|
||||
|
||||
.controller('settingsController', function ($scope, $state, SweetAlert, utilsService, $analytics,
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
|
||||
chrome.storage.local.set(obj, function () {
|
||||
cryptoService.getKeyHash(function (keyHash) {
|
||||
cryptoService.getKeyHash().then(function (keyHash) {
|
||||
if (keyHash) {
|
||||
cryptoService.toggleKey();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular
|
||||
angular
|
||||
.module('bit.tools')
|
||||
|
||||
.controller('toolsExportController', function ($scope, $state, toastr, $q, $analytics,
|
||||
@@ -24,8 +24,9 @@
|
||||
|
||||
userService.getEmail(function (email) {
|
||||
var key = cryptoService.makeKey($scope.masterPassword, email);
|
||||
cryptoService.hashPassword($scope.masterPassword, key, function (keyHash) {
|
||||
cryptoService.getKeyHash(function (storedKeyHash) {
|
||||
cryptoService.hashPassword($scope.masterPassword, key).then(function (keyHash) {
|
||||
return cryptoService.getKeyHash();
|
||||
}).then(function (storedKeyHash) {
|
||||
if (storedKeyHash && keyHash && storedKeyHash === keyHash) {
|
||||
deferred.resolve();
|
||||
}
|
||||
@@ -34,7 +35,6 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ export default class CryptoService {
|
||||
return self.utilsService.saveObjToStorage(Keys.key, key.keyB64);
|
||||
}
|
||||
|
||||
// TODO: convert uses to promises
|
||||
setKeyHash(keyHash: string) {
|
||||
setKeyHash(keyHash: string): Promise<{}> {
|
||||
this.keyHash = keyHash;
|
||||
return this.utilsService.saveObjToStorage(Keys.keyHash, keyHash);
|
||||
}
|
||||
@@ -66,7 +65,7 @@ export default class CryptoService {
|
||||
}
|
||||
|
||||
// TODO: proper response model type for orgs
|
||||
setOrgKeys(orgs: any) {
|
||||
setOrgKeys(orgs: any): Promise<{}> {
|
||||
const orgKeys: any = {};
|
||||
for (const org of orgs) {
|
||||
orgKeys[org.id] = org.key;
|
||||
@@ -93,7 +92,6 @@ export default class CryptoService {
|
||||
return key == null ? null : this.key;
|
||||
}
|
||||
|
||||
// TODO: convert uses to promises
|
||||
getKeyHash(): Promise<string> {
|
||||
if (this.keyHash != null) {
|
||||
return Promise.resolve(this.keyHash);
|
||||
@@ -259,7 +257,6 @@ export default class CryptoService {
|
||||
return new SymmetricCryptoKey(keyBytes);
|
||||
}
|
||||
|
||||
// TODO: convert uses to promises
|
||||
async hashPassword(password: string, key: SymmetricCryptoKey): Promise<string> {
|
||||
const storedKey = await this.getKey();
|
||||
key = key || storedKey;
|
||||
|
||||
Reference in New Issue
Block a user