Added decryption to proper credentialelement after creating a new credential

Signed-off-by: fnuesse <felix.nuesse@t-online.de>
This commit is contained in:
fnuesse 2018-11-23 01:29:48 +01:00
parent d90626bc8e
commit ce138267d2
No known key found for this signature in database
GPG key ID: 2089A3431243E819
3 changed files with 71 additions and 28 deletions

View file

@ -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);
}
/**

View file

@ -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;
});

View file

@ -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.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,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);
};