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