diff --git a/controller/credentialcontroller.php b/controller/credentialcontroller.php index e820fd62..d18e7855 100644 --- a/controller/credentialcontroller.php +++ b/controller/credentialcontroller.php @@ -104,7 +104,18 @@ class CredentialController extends ApiController { '', array(), $link, $this->userId, Activity::TYPE_ITEM_ACTION); } - return new JSONResponse($credential); + + + //fetch the proper credentialelement, the returned element from createCredential is not usable in the frontend. + $credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId); + foreach ($credentials as &$value) { + if($value->getGuid() == $credential->getGuid()){ + return new JSONResponse($value); + } + } + + //return old value as fallback + return new JSONResponse($credentials); } /** @@ -258,6 +269,16 @@ class CredentialController extends ApiController { $credential = $this->credentialService->updateCredential($credential); + + //fetch the proper credentialelement, the returned element from createCredential is not usable in the frontend. + $credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId); + foreach ($credentials as &$value) { + if($value->getGuid() == $credential->getGuid()){ + return new JSONResponse($value); + } + } + + //return old value as fallback return new JSONResponse($credential); } diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index 0a22a0e2..0ad511aa 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -134,18 +134,16 @@ }); }; - - 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(); @@ -320,6 +318,10 @@ $scope.view_mode = viewMode; }; + $rootScope.$on('push_decrypted_credential_to_list', function () { + $rootScope.$broadcast('credentials_loaded'); + }); + $scope.filterOptions = { filterText: '', fields: ['label', 'username', 'email', 'custom_fields'] @@ -330,7 +332,6 @@ $scope.filterOptions.filterText=args; }); - $scope.filtered_credentials = []; $scope.$watch('[selectedtags, filterOptions, delete_time, active_vault.credentials]', function () { if (!$scope.active_vault) { @@ -350,7 +351,6 @@ } } } - }, true); $scope.no_credentials_label=[]; @@ -536,7 +536,7 @@ } $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 6f1abc9a..b7a11eaf 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -32,7 +32,7 @@ * Controller of the passmanApp */ angular.module('passmanApp') - .controller('CredentialEditCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'FileService', 'EncryptService', 'TagService', 'NotificationService', 'ShareService', '$translate', '$rootScope', + .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')) { @@ -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.saving = false; + + $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,15 @@ 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); + $scope.updateExistingListWithCredential(new_cred); }); + + } else { var key, _credential; @@ -344,11 +347,13 @@ if(_credential.description && _credential.description !== "") { _credential.description = _credential.description.replace(regex, ""); } - CredentialService.updateCredential(_credential, _useKey).then(function () { - $scope.saving = false; + 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); }); } $scope.refreshListWithSaved(); @@ -366,6 +371,37 @@ $rootScope.vaultCache[$scope.active_vault.guid] = current_vault; }; + $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; + + + 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) { + NotificationService.showNotification($translate.instant('error.decrypt'), 5000); + console.log(e); + } + }; + $scope.cancel = function () { $location.path('/vault/' + $routeParams.vault_id); };