From ce138267d2450b2d2480d07485495b74fb784624 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Fri, 23 Nov 2018 01:29:48 +0100 Subject: Added decryption to proper credentialelement after creating a new credential Signed-off-by: fnuesse --- js/app/controllers/credential.js | 31 +++++++++++++------- js/app/controllers/edit_credential.js | 53 ++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 26 deletions(-) (limited to 'js') diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index 303635f1..4a52dc5c 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -59,7 +59,7 @@ $scope.active_vault = vault; $scope.active_vault.vaultKey = vaultKey; if(!$rootScope.vaultCache){ - $rootScope.vaultCache = []; + $rootScope.vaultCache = []; } VaultService.setActiveVault($scope.active_vault); for (var i = 0; i < _credentials.length; i++) { @@ -136,16 +136,27 @@ + $rootScope.$on('push_decrypted_credential_to_list', function (event, args) { + console.log("Update List with:"); + console.log(args); + //$rootScope.active_vault.credentials.push(args); + updateList(args); + }); + + var updateList = function (args) { + $scope.credentials.push(args); + }; + var refresh_data_interval = null; if ($scope.active_vault) { $scope.$parent.selectedVault = true; if($rootScope.vaultCache && $rootScope.vaultCache[$scope.active_vault.guid]){ - $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; - $rootScope.$broadcast('credentials_loaded'); - $scope.show_spinner = false; - } else { - fetchCredentials(); - } + $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; + $rootScope.$broadcast('credentials_loaded'); + $scope.show_spinner = false; + } else { + fetchCredentials(); + } getPendingShareRequests(); refresh_data_interval = $interval(function () { fetchCredentials(); @@ -411,11 +422,11 @@ $rootScope.$on('logout', function () { if($scope.active_vault) { - $rootScope.vaultCache[$scope.active_vault.guid] = null; - } + $rootScope.vaultCache[$scope.active_vault.guid] = null; + } $scope.active_vault = null; $scope.credentials = []; -// $scope.$parent.selectedVault = false; + //$scope.$parent.selectedVault = false; }); diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 5c9ad4f0..3199d600 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -32,8 +32,8 @@ * Controller of the passmanApp */ angular.module('passmanApp') - .controller('CredentialEditCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'FileService', 'EncryptService', 'TagService', 'NotificationService', 'ShareService', '$translate', - function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, FileService, EncryptService, TagService, NotificationService, ShareService, $translate) { + .controller('CredentialEditCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'FileService', 'EncryptService', 'TagService', 'NotificationService', 'ShareService', '$translate','$rootScope', + function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, FileService, EncryptService, TagService, NotificationService, ShareService, $translate, $rootScope) { $scope.active_vault = VaultService.getActiveVault(); if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) { if (!$scope.active_vault) { @@ -186,12 +186,12 @@ }; $scope.addFileToCustomField = function (file) { - $scope.new_custom_field.value = { - filename: file.name, - size: file.size, - mimetype: file.type, - data: file.data - }; + $scope.new_custom_field.value = { + filename: file.name, + size: file.size, + mimetype: file.type, + data: file.data + }; $scope.$digest(); }; @@ -290,19 +290,19 @@ }; $scope.$digest(); }; + $scope.saving = false; - $scope.saveCredential = function () { - $scope.saving = true; + $scope.saveCredential = function () { + $scope.saving = true; if ($scope.new_custom_field.label && $scope.new_custom_field.value) { $scope.storedCredential.custom_fields.push(angular.copy($scope.new_custom_field)); } - if ($scope.storedCredential.password !== $scope.storedCredential.password_repeat){ - $scope.saving = false; - NotificationService.showNotification($translate.instant('password.do.not.match'), 5000); + $scope.saving = false; + NotificationService.showNotification($translate.instant('password.do.not.match'), 5000); return; } @@ -312,12 +312,17 @@ if (!$scope.storedCredential.credential_id) { $scope.storedCredential.vault_id = $scope.active_vault.vault_id; - CredentialService.createCredential($scope.storedCredential).then(function () { - $scope.saving = false; + CredentialService.createCredential($scope.storedCredential).then(function (new_cred) { + $scope.saving = false; $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.created'), 5000); + console.log("new cred"); + console.log(new_cred); + $scope.updateExistingListWithCredential(new_cred); }); + + } else { var key, _credential; @@ -345,7 +350,7 @@ _credential.description = _credential.description.replace(regex, ""); } CredentialService.updateCredential(_credential, _useKey).then(function () { - $scope.saving = false; + $scope.saving = false; SettingsService.setSetting('edit_credential', null); $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.updated'), 5000); @@ -354,6 +359,22 @@ }; + $scope.updateExistingListWithCredential = function (credential) { + try { + if (!credential.shared_key) { + credential = CredentialService.decryptCredential(credential); + } else { + var enc_key = EncryptService.decryptString(credential.shared_key); + credential = ShareService.decryptSharedCredential(credential, enc_key); + } + credential.tags_raw = credential.tags; + $rootScope.$broadcast('push_decrypted_credential_to_list', credential); + } catch (e) { + NotificationService.showNotification($translate.instant('error.decrypt'), 5000); + console.log(e); + } + }; + $scope.cancel = function () { $location.path('/vault/' + $routeParams.vault_id); }; -- cgit v1.2.3 From abaedc1e38ccbbaac182b04437cdb4741e6c852a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Fri, 23 Nov 2018 18:02:34 +0100 Subject: Updated main listview after new creation of credential MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix Nüsse --- js/app/controllers/credential.js | 54 ++++++++++++++--------------------- js/app/controllers/edit_credential.js | 3 ++ 2 files changed, 25 insertions(+), 32 deletions(-) (limited to 'js') diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index 4a52dc5c..f6d445c1 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -134,19 +134,6 @@ }); }; - - - $rootScope.$on('push_decrypted_credential_to_list', function (event, args) { - console.log("Update List with:"); - console.log(args); - //$rootScope.active_vault.credentials.push(args); - updateList(args); - }); - - var updateList = function (args) { - $scope.credentials.push(args); - }; - var refresh_data_interval = null; if ($scope.active_vault) { $scope.$parent.selectedVault = true; @@ -331,32 +318,35 @@ $scope.view_mode = viewMode; }; + $rootScope.$on('push_decrypted_credential_to_list', function () { + $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; + $rootScope.$broadcast('credentials_loaded'); + }); + $scope.filterOptions = { filterText: '', fields: ['label', 'username', 'email', 'custom_fields'] }; - $scope.filtered_credentials = []; $scope.$watch('[selectedtags, filterOptions, delete_time, active_vault.credentials]', function () { - if (!$scope.active_vault) { - return; - } - if ($scope.active_vault.credentials) { - var credentials = angular.copy($scope.active_vault.credentials); - var filtered_credentials = $filter('credentialSearch')(credentials, $scope.filterOptions); - filtered_credentials = $filter('tagFilter')(filtered_credentials, $scope.selectedtags); - filtered_credentials = $filter('filter')(filtered_credentials, {hidden: 0}); - $scope.filtered_credentials = filtered_credentials; - $scope.filterOptions.selectedtags = angular.copy($scope.selectedtags); - for (var i = 0; i < $scope.active_vault.credentials.length; i++) { - var _credential = $scope.active_vault.credentials[i]; - if (_credential.tags) { - TagService.addTags(_credential.tags); - } - } - } - + if (!$scope.active_vault) { + return; + } + if ($scope.active_vault.credentials) { + var credentials = angular.copy($scope.active_vault.credentials); + var filtered_credentials = $filter('credentialSearch')(credentials, $scope.filterOptions); + filtered_credentials = $filter('tagFilter')(filtered_credentials, $scope.selectedtags); + filtered_credentials = $filter('filter')(filtered_credentials, {hidden: 0}); + $scope.filtered_credentials = filtered_credentials; + $scope.filterOptions.selectedtags = angular.copy($scope.selectedtags); + for (var i = 0; i < $scope.active_vault.credentials.length; i++) { + var _credential = $scope.active_vault.credentials[i]; + if (_credential.tags) { + TagService.addTags(_credential.tags); + } + } + } }, true); $scope.selectedtags = []; diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 3199d600..14acc04c 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -368,7 +368,10 @@ credential = ShareService.decryptSharedCredential(credential, enc_key); } credential.tags_raw = credential.tags; + + $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); $rootScope.$broadcast('push_decrypted_credential_to_list', credential); + } catch (e) { NotificationService.showNotification($translate.instant('error.decrypt'), 5000); console.log(e); -- cgit v1.2.3 From ea23930352037553d75dc25ca9de47a1ce12ad69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Fri, 23 Nov 2018 18:15:18 +0100 Subject: Added proper returnvalue to updatemethod of credentials and add the resulting value to the list if it does not exist or replace it if it exists Fixed Nullpointer on listadd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix Nüsse --- js/app/controllers/credential.js | 1 - js/app/controllers/edit_credential.js | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index f6d445c1..cb82461d 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -319,7 +319,6 @@ }; $rootScope.$on('push_decrypted_credential_to_list', function () { - $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; $rootScope.$broadcast('credentials_loaded'); }); diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 14acc04c..0cfaff6a 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -317,8 +317,6 @@ $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.created'), 5000); - console.log("new cred"); - console.log(new_cred); $scope.updateExistingListWithCredential(new_cred); }); @@ -349,11 +347,13 @@ if(_credential.description && _credential.description !== "") { _credential.description = _credential.description.replace(regex, ""); } - CredentialService.updateCredential(_credential, _useKey).then(function () { + CredentialService.updateCredential(_credential, _useKey).then(function (updated_cred) { $scope.saving = false; SettingsService.setSetting('edit_credential', null); $location.path('/vault/' + $routeParams.vault_id); NotificationService.showNotification($translate.instant('credential.updated'), 5000); + + $scope.updateExistingListWithCredential(updated_cred); }); } @@ -369,7 +369,19 @@ } credential.tags_raw = credential.tags; - $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); + + var found=false; + var credList=$rootScope.vaultCache[$scope.active_vault.guid].credentials; + for (var i = 0; i < credList.length; i++) { + if(credList[i].credential_id==credential.credential_id){ + $rootScope.vaultCache[$scope.active_vault.guid].credentials[i]=credential; + found=true; + } + } + + if(!found){ + $rootScope.vaultCache[$scope.active_vault.guid].credentials.push(credential); + } $rootScope.$broadcast('push_decrypted_credential_to_list', credential); } catch (e) { -- cgit v1.2.3