1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

re-worked change password, email, and update key

This commit is contained in:
Kyle Spearrin
2017-07-31 22:53:27 -04:00
parent dad3cd9414
commit 747b5608e8
7 changed files with 97 additions and 143 deletions

View File

@@ -1,8 +1,8 @@
angular
.module('bit.settings')
.controller('settingsUpdateKeyController', function ($scope, $state, apiService, $uibModalInstance,
cryptoService, authService, cipherService, validationService, toastr, $analytics) {
.controller('settingsUpdateKeyController', function ($scope, $state, apiService, $uibModalInstance, cipherService,
cryptoService, authService, validationService, toastr, $analytics, $q) {
$analytics.eventTrack('settingsUpdateKeyController', { category: 'Modal' });
$scope.save = function (form) {
@@ -13,27 +13,68 @@
return;
}
$scope.processing = true;
$scope.savePromise = cryptoService.hashPassword($scope.masterPassword).then(function (hash) {
return cipherService.updateKey(hash, function () {
return null;
}, function () {
return null;
});
return updateKey(hash);
}).then(function () {
$uibModalInstance.dismiss('cancel');
authService.logOut();
$analytics.eventTrack('Key Updated');
return $state.go('frontend.login.info');
}, function (e) {
throw e ? e : 'Error occurred.';
}).then(function () {
toastr.success('Please log back in. If you are using other bitwarden applications, ' +
'log out and back in to those as well.', 'Key Updated', { timeOut: 10000 });
}, function () {
$uibModalInstance.dismiss('cancel');
toastr.error('Something went wrong.', 'Oh No!');
});
};
function updateKey(masterPasswordHash) {
var madeEncKey = cryptoService.makeEncKey(null);
var reencryptedLogins = [];
var loginsPromise = apiService.logins.list({}, function (encryptedLogins) {
var filteredEncryptedLogins = [];
for (var i = 0; i < encryptedLogins.Data.length; i++) {
if (encryptedLogins.Data[i].OrganizationId) {
continue;
}
filteredEncryptedLogins.push(encryptedLogins.Data[i]);
}
var unencryptedLogins = cipherService.decryptLogins(filteredEncryptedLogins);
reencryptedLogins = cipherService.encryptLogins(unencryptedLogins, madeEncKey.encKey);
}).$promise;
var reencryptedFolders = [];
var foldersPromise = apiService.folders.list({}, function (encryptedFolders) {
var unencryptedFolders = cipherService.decryptFolders(encryptedFolders.Data);
reencryptedFolders = cipherService.encryptFolders(unencryptedFolders, madeEncKey.encKey);
}).$promise;
var privateKey = cryptoService.getPrivateKey('raw'),
reencryptedPrivateKey = null;
if (privateKey) {
reencryptedPrivateKey = cryptoService.encrypt(privateKey, madeEncKey.encKey, 'raw');
}
return $q.all([loginsPromise, foldersPromise]).then(function () {
var request = {
masterPasswordHash: masterPasswordHash,
ciphers: reencryptedLogins,
folders: reencryptedFolders,
privateKey: reencryptedPrivateKey,
key: madeEncKey.encKeyEnc
};
return apiService.accounts.putKey(request).$promise;
}, function () {
throw 'Error while encrypting data.';
}).then(function () {
cryptoService.setEncKey(madeEncKey.encKey, null, true);
});
}
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};