1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

convert to promises. loginService cipher refactor

This commit is contained in:
Kyle Spearrin
2017-10-13 17:07:20 -04:00
parent 294817d17b
commit 2b5915b257
15 changed files with 526 additions and 527 deletions

View File

@@ -1,7 +1,7 @@
angular
.module('bit.vault')
.controller('vaultAttachmentsController', function ($scope, $state, $stateParams, loginService, $q, toastr,
.controller('vaultAttachmentsController', function ($scope, $state, $stateParams, loginService, toastr,
SweetAlert, utilsService, $analytics, i18nService, cryptoService, tokenService) {
$scope.i18n = i18nService;
utilsService.initListSectionItemListeners($(document), angular);
@@ -10,44 +10,44 @@ angular
$scope.canAccessAttachments = $scope.isPremium;
$scope.hasUpdatedKey = false;
loginService.get($stateParams.id, function (login) {
$q.when(login.decrypt()).then(function (model) {
$scope.login = model;
$scope.canAccessAttachments = $scope.isPremium || !!$scope.login.organizationId;
loginService.get($stateParams.id).then(function (login) {
return login.decrypt();
}).then(function (model) {
$scope.login = model;
$scope.canAccessAttachments = $scope.isPremium || !!$scope.login.organizationId;
if (!$scope.canAccessAttachments) {
SweetAlert.swal({
title: i18nService.premiumRequired,
text: i18nService.premiumRequiredDesc,
showCancelButton: true,
confirmButtonText: i18nService.learnMore,
cancelButtonText: i18nService.cancel
}, function (confirmed) {
if (confirmed) {
chrome.tabs.create({ url: 'https://vault.bitwarden.com/#/?premium=purchase' });
}
});
return;
}
else {
cryptoService.getEncKey().then(function (key) {
$scope.hasUpdatedKey = !!key;
if (!$scope.hasUpdatedKey) {
SweetAlert.swal({
title: i18nService.featureUnavailable,
text: i18nService.updateKey,
showCancelButton: true,
confirmButtonText: i18nService.learnMore,
cancelButtonText: i18nService.cancel
}, function (confirmed) {
if (confirmed) {
chrome.tabs.create({ url: 'https://help.bitwarden.com/article/update-encryption-key/' });
}
});
}
});
}
});
if (!$scope.canAccessAttachments) {
SweetAlert.swal({
title: i18nService.premiumRequired,
text: i18nService.premiumRequiredDesc,
showCancelButton: true,
confirmButtonText: i18nService.learnMore,
cancelButtonText: i18nService.cancel
}, function (confirmed) {
if (confirmed) {
chrome.tabs.create({ url: 'https://vault.bitwarden.com/#/?premium=purchase' });
}
});
return;
}
else {
cryptoService.getEncKey().then(function (key) {
$scope.hasUpdatedKey = !!key;
if (!$scope.hasUpdatedKey) {
SweetAlert.swal({
title: i18nService.featureUnavailable,
text: i18nService.updateKey,
showCancelButton: true,
confirmButtonText: i18nService.learnMore,
cancelButtonText: i18nService.cancel
}, function (confirmed) {
if (confirmed) {
chrome.tabs.create({ url: 'https://help.bitwarden.com/article/update-encryption-key/' });
}
});
}
});
}
});
$scope.submitPromise = null;
@@ -69,8 +69,8 @@ angular
return deferred.promise;
}
$scope.submitPromise = $q.when(loginService.saveAttachmentWithServer($scope.login, files[0])).then(function (login) {
$q.when(login.decrypt()).then(function (model) {
$scope.submitPromise = loginService.saveAttachmentWithServer($scope.login, files[0]).then(function (login) {
login.decrypt().then(function (model) {
$scope.login = model;
});
$analytics.eventTrack('Added Attachment');
@@ -100,7 +100,7 @@ angular
cancelButtonText: i18nService.no
}, function (confirmed) {
if (confirmed) {
$q.when(loginService.deleteAttachmentWithServer($stateParams.id, attachment.id)).then(function () {
loginService.deleteAttachmentWithServer($stateParams.id, attachment.id).then(function () {
var index = $scope.login.attachments.indexOf(attachment);
if (index > -1) {
$scope.login.attachments.splice(index, 1);

View File

@@ -2,7 +2,7 @@ angular
.module('bit.vault')
.controller('vaultEditLoginController', function ($scope, $state, $stateParams, loginService, folderService,
cryptoService, $q, toastr, SweetAlert, utilsService, $analytics, i18nService, constantsService) {
cryptoService, toastr, SweetAlert, utilsService, $analytics, i18nService, constantsService) {
$scope.i18n = i18nService;
$scope.constants = constantsService;
$scope.showAttachments = !utilsService.isEdge();
@@ -21,14 +21,14 @@ angular
angular.extend($scope.login, $stateParams.login);
}
else {
loginService.get(loginId, function (login) {
$q.when(login.decrypt()).then(function (model) {
$scope.login = model;
});
loginService.get(loginId).then(function (login) {
return login.decrypt();
}).then(function (model) {
$scope.login = model;
});
}
$q.when(folderService.getAllDecrypted()).then(function (folders) {
folderService.getAllDecrypted().then(function (folders) {
$scope.folders = folders;
});
@@ -41,9 +41,9 @@ angular
return;
}
$scope.savePromise = $q.when(loginService.encrypt(model)).then(function (loginModel) {
$scope.savePromise = loginService.encrypt(model).then(function (loginModel) {
var login = new Login(loginModel, true);
return $q.when(loginService.saveWithServer(login)).then(function (login) {
return loginService.saveWithServer(login).then(function (login) {
$analytics.eventTrack('Edited Login');
toastr.success(i18nService.editedLogin);
$scope.close();
@@ -60,7 +60,7 @@ angular
cancelButtonText: i18nService.no
}, function (confirmed) {
if (confirmed) {
$q.when(loginService.deleteWithServer(loginId)).then(function () {
loginService.deleteWithServer(loginId).then(function () {
$analytics.eventTrack('Deleted Login');
toastr.success(i18nService.deletedLogin);
$state.go('tabs.vault', {

View File

@@ -1,7 +1,7 @@
angular
.module('bit.vault')
.controller('vaultViewLoginController', function ($scope, $state, $stateParams, loginService, toastr, $q,
.controller('vaultViewLoginController', function ($scope, $state, $stateParams, loginService, toastr,
$analytics, i18nService, utilsService, totpService, $timeout, tokenService, $window, cryptoService, SweetAlert,
constantsService) {
$scope.constants = constantsService;
@@ -12,45 +12,45 @@ angular
$scope.isPremium = tokenService.getPremium();
$scope.login = null;
loginService.get($stateParams.loginId, function (login) {
loginService.get($stateParams.loginId).then(function (login) {
if (!login) {
return;
}
$q.when(login.decrypt()).then(function (model) {
$scope.login = model;
return login.decrypt();
}).then(function (model) {
$scope.login = model;
if (model.password) {
$scope.login.maskedPassword = $scope.maskValue(model.password);
}
if (model.password) {
$scope.login.maskedPassword = $scope.maskValue(model.password);
}
if (model.uri) {
$scope.login.showLaunch = model.uri.startsWith('http://') || model.uri.startsWith('https://');
var domain = utilsService.getDomain(model.uri);
if (domain) {
$scope.login.website = domain;
}
else {
$scope.login.website = model.uri;
}
if (model.uri) {
$scope.login.showLaunch = model.uri.startsWith('http://') || model.uri.startsWith('https://');
var domain = utilsService.getDomain(model.uri);
if (domain) {
$scope.login.website = domain;
}
else {
$scope.login.showLaunch = false;
$scope.login.website = model.uri;
}
}
else {
$scope.login.showLaunch = false;
}
if (model.totp && (login.organizationUseTotp || tokenService.getPremium())) {
totpUpdateCode();
totpTick();
if (totpInterval) {
clearInterval(totpInterval);
}
if (model.totp && (login.organizationUseTotp || tokenService.getPremium())) {
totpUpdateCode();
totpInterval = setInterval(function () {
totpTick();
if (totpInterval) {
clearInterval(totpInterval);
}
totpInterval = setInterval(function () {
totpTick();
}, 1000);
}
});
}, 1000);
}
});
$scope.edit = function (login) {