mirror of
https://github.com/nextcloud/passman.git
synced 2024-09-21 15:26:33 +08:00
Added decryption to proper credentialelement after creating a new credential
Signed-off-by: fnuesse <felix.nuesse@t-online.de>
This commit is contained in:
parent
d90626bc8e
commit
ce138267d2
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -136,6 +136,17 @@
|
|||
|
||||
|
||||
|
||||
$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;
|
||||
|
@ -415,7 +426,7 @@
|
|||
}
|
||||
$scope.active_vault = null;
|
||||
$scope.credentials = [];
|
||||
// $scope.$parent.selectedVault = false;
|
||||
//$scope.$parent.selectedVault = false;
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -290,16 +290,16 @@
|
|||
};
|
||||
$scope.$digest();
|
||||
};
|
||||
|
||||
$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);
|
||||
|
@ -312,12 +312,17 @@
|
|||
|
||||
if (!$scope.storedCredential.credential_id) {
|
||||
$scope.storedCredential.vault_id = $scope.active_vault.vault_id;
|
||||
CredentialService.createCredential($scope.storedCredential).then(function () {
|
||||
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;
|
||||
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue