2016-10-08 01:56:29 +08:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngdoc function
|
|
|
|
* @name passmanApp.controller:RevisionCtrl
|
|
|
|
* @description
|
|
|
|
* # RevisionCtrl
|
|
|
|
* Controller of the passmanApp
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
|
|
|
.controller('RevisionCtrl', ['$scope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$rootScope', 'NotificationService', '$filter', 'ShareService', 'EncryptService',
|
|
|
|
function ($scope, SettingsService, VaultService, CredentialService, $location, $routeParams, $rootScope, NotificationService, $filter, ShareService, EncryptService) {
|
|
|
|
$scope.active_vault = VaultService.getActiveVault();
|
|
|
|
if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) {
|
|
|
|
if (!$scope.active_vault) {
|
|
|
|
$location.path('/');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (SettingsService.getSetting('defaultVault') && SettingsService.getSetting('defaultVaultPass')) {
|
|
|
|
var _vault = angular.copy(SettingsService.getSetting('defaultVault'));
|
|
|
|
_vault.vaultKey = SettingsService.getSetting('defaultVaultPass');
|
|
|
|
VaultService.setActiveVault(_vault);
|
|
|
|
VaultService.getVault(_vault).then(function (vault) {
|
|
|
|
vault.vaultKey = SettingsService.getSetting('defaultVaultPass');
|
|
|
|
VaultService.setActiveVault(vault);
|
|
|
|
$scope.active_vault = vault;
|
|
|
|
$scope.$parent.selectedVault = true;
|
|
|
|
});
|
2016-10-06 01:41:47 +08:00
|
|
|
}
|
2016-10-06 00:24:36 +08:00
|
|
|
}
|
2016-10-06 00:39:00 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
if ($scope.active_vault) {
|
|
|
|
$scope.$parent.selectedVault = true;
|
|
|
|
}
|
|
|
|
var storedCredential = SettingsService.getSetting('revision_credential');
|
|
|
|
|
|
|
|
var getRevisions = function () {
|
|
|
|
CredentialService.getRevisions($scope.storedCredential.guid).then(function (revisions) {
|
|
|
|
$scope.revisions = revisions;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!storedCredential) {
|
|
|
|
CredentialService.getCredential($routeParams.credential_id).then(function (result) {
|
|
|
|
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(result));
|
|
|
|
getRevisions();
|
|
|
|
});
|
2016-10-06 00:39:00 +08:00
|
|
|
} else {
|
2016-10-08 01:56:29 +08:00
|
|
|
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(storedCredential));
|
|
|
|
getRevisions();
|
2016-10-06 00:24:36 +08:00
|
|
|
}
|
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
$scope.selectRevision = function (revision) {
|
|
|
|
var key;
|
|
|
|
$scope.selectedRevision = angular.copy(revision);
|
|
|
|
|
|
|
|
if (!$scope.storedCredential.hasOwnProperty('acl') && $scope.storedCredential.hasOwnProperty('shared_key')) {
|
|
|
|
if ($scope.storedCredential.shared_key) {
|
|
|
|
key = EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key));
|
2016-09-24 18:59:19 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-08 01:56:29 +08:00
|
|
|
if ($scope.storedCredential.hasOwnProperty('acl')) {
|
|
|
|
key = EncryptService.decryptString(angular.copy($scope.storedCredential.acl.shared_key));
|
|
|
|
}
|
2016-10-06 00:52:14 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
if (key) {
|
|
|
|
$scope.selectedRevision.credential_data = ShareService.decryptSharedCredential(angular.copy(revision.credential_data), key);
|
|
|
|
} else {
|
|
|
|
$scope.selectedRevision.credential_data = CredentialService.decryptCredential(angular.copy(revision.credential_data));
|
2016-10-06 01:33:07 +08:00
|
|
|
}
|
2016-10-06 00:52:14 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
$rootScope.$emit('app_menu', true);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.closeSelected = function () {
|
2016-09-24 18:59:19 +08:00
|
|
|
$rootScope.$emit('app_menu', false);
|
2016-10-08 01:56:29 +08:00
|
|
|
$scope.selectedRevision = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteRevision = function (revision) {
|
|
|
|
CredentialService.deleteRevision($scope.storedCredential.guid, revision.revision_id).then(function () {
|
|
|
|
for (var i = 0; i < $scope.revisions.length; i++) {
|
|
|
|
if ($scope.revisions[i].revision_id === revision.revision_id) {
|
|
|
|
$scope.revisions.splice(i, 1);
|
|
|
|
NotificationService.showNotification('Revision deleted', 5000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.restoreRevision = function (revision) {
|
|
|
|
var key;
|
|
|
|
var _revision = angular.copy(revision);
|
|
|
|
var _credential = _revision.credential_data;
|
2016-09-24 18:59:19 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
if (!$scope.storedCredential.hasOwnProperty('acl') && $scope.storedCredential.hasOwnProperty('shared_key')) {
|
|
|
|
if ($scope.storedCredential.shared_key) {
|
|
|
|
key = EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($scope.storedCredential.hasOwnProperty('acl')) {
|
|
|
|
key = EncryptService.decryptString(angular.copy($scope.storedCredential.acl.shared_key));
|
|
|
|
}
|
|
|
|
if (key) {
|
|
|
|
_credential = ShareService.encryptSharedCredential(_credential, key);
|
|
|
|
}
|
|
|
|
delete _credential.shared_key;
|
|
|
|
|
|
|
|
//Used in activity
|
|
|
|
_credential.revision_created = $filter('date')(_revision.created * 1000, "dd-MM-yyyy @ HH:mm:ss");
|
2016-10-13 02:12:28 +08:00
|
|
|
CredentialService.updateCredential(_credential, (key)).then(function () {
|
2016-10-08 01:56:29 +08:00
|
|
|
SettingsService.setSetting('revision_credential', null);
|
|
|
|
$rootScope.$emit('app_menu', false);
|
|
|
|
$location.path('/vault/' + $routeParams.vault_id);
|
|
|
|
NotificationService.showNotification('Revision restored!', 5000);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancel = function () {
|
|
|
|
$location.path('/vault/' + $routeParams.vault_id);
|
|
|
|
$scope.storedCredential = null;
|
|
|
|
SettingsService.setSetting('revision_credential', null);
|
|
|
|
};
|
2016-09-24 16:59:16 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
}]);
|
2016-09-24 16:59:16 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
}());
|