From f7ea3b996539c2b07149083474ea4fb0fc05d6f9 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 19:51:36 +0200 Subject: [PATCH 01/12] Rename Password tool to Password Audit --- js/app/controllers/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index 1d86ac24..dc5d8247 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -17,7 +17,7 @@ angular.module('passmanApp') url: 'views/partials/forms/settings/general_settings.html' }, { - title: 'Password Tool', + title: 'Password Audit', url: 'views/partials/forms/settings/tool.html' }, From d2c02ce32b91e24376f0034751a99952b4074568 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 20:26:59 +0200 Subject: [PATCH 02/12] Add settings to vault table --- appinfo/database.xml | 6 +++++- appinfo/info.xml | 2 +- lib/Db/Vault.php | 8 +++++--- lib/Db/VaultMapper.php | 14 ++++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/appinfo/database.xml b/appinfo/database.xml index 0536c2ac..6901f66b 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -36,7 +36,11 @@ 100 true - + + settings + clob + false + created integer diff --git a/appinfo/info.xml b/appinfo/info.xml index ac6ea8e1..bcd27f37 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ A password manager for Nextcloud AGPL Sander Brand - 1.0.2.9 + 1.0.2.10 Passman other https://github.com/nextcloud/passman/ diff --git a/lib/Db/Vault.php b/lib/Db/Vault.php index 4a43ff11..ca312290 100644 --- a/lib/Db/Vault.php +++ b/lib/Db/Vault.php @@ -31,6 +31,8 @@ use \OCP\AppFramework\Db\Entity; * @method string getPrivateSharingKey() * @method void setSharingKeysGenerated(integer $value) * @method integer getSharingKeysGenerated() + * @method void setSettings(integer $value) + * @method integer getSettings() */ @@ -46,11 +48,13 @@ class Vault extends Entity implements \JsonSerializable{ protected $publicSharingKey; protected $privateSharingKey; protected $sharingKeysGenerated; + protected $settings; + public function __construct() { // add types in constructor $this->addType('created', 'integer'); $this->addType('lastAccess', 'integer'); - $this->addType('sharing_keys_generated', 'integer'); + $this->addType('sharingKeysGenerated', 'integer'); } /** * Turns entity attributes into an array @@ -61,9 +65,7 @@ class Vault extends Entity implements \JsonSerializable{ 'guid' => $this->getGuid(), 'name' => $this->getName(), 'created' => $this->getCreated(), - 'private_sharing_key' => $this->getPrivateSharingKey(), 'public_sharing_key' => $this->getPublicSharingKey(), - 'sharing_keys_generated' => $this->getSharingKeysGenerated(), 'last_access' => $this->getlastAccess(), ]; } diff --git a/lib/Db/VaultMapper.php b/lib/Db/VaultMapper.php index 0eadd459..0c7e3d6d 100644 --- a/lib/Db/VaultMapper.php +++ b/lib/Db/VaultMapper.php @@ -26,12 +26,13 @@ class VaultMapper extends Mapper { * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result */ - public function find($vault_id) { + public function find($vault_id, $user_id) { $sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' . - 'WHERE `user_id` = ?'; - return $this->findEntities($sql, [$vault_id]); + 'WHERE `id`= ? and `user_id` = ?'; + return $this->findEntities($sql, [$vault_id, $user_id]); } + public function findVaultsFromUser($userId){ $sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' . 'WHERE `user_id` = ? '; @@ -45,14 +46,15 @@ class VaultMapper extends Mapper { $vault->setUserId($userId); $vault->setGuid($this->utils->GUID()); $vault->setCreated($this->utils->getTime()); - $vault->setlastAccess(0); + $vault->setLastAccess(0); return parent::insert($vault); } - public function setLastAccess($vault_id){ + public function setLastAccess($vault_id, $user_id){ $vault = new Vault(); $vault->setId($vault_id); - $vault->setlastAccess(time()); + $vault->setUserId($user_id); + $vault->setLastAccess(time()); $this->update($vault); } From 370b9b832e744a46371ab9157243422f176480d7 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 20:27:52 +0200 Subject: [PATCH 03/12] Change api/v2/vaults/{id} response format --- controller/vaultcontroller.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php index 6ef5db83..5c920546 100644 --- a/controller/vaultcontroller.php +++ b/controller/vaultcontroller.php @@ -56,8 +56,10 @@ class VaultController extends ApiController { */ public function get($vault_id) { $credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId); - $this->vaultService->setLastAccess($vault_id); - return new JSONResponse($credentials); + $result = $this->vaultService->getById($vault_id, $this->userId); + $result['credentials'] = $credentials; + $this->vaultService->setLastAccess($vault_id, $this->userId); + return new JSONResponse($result); } /** From 4463fa7d3c9ff1e702d6e8eaefa1a8278b4212c2 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 20:28:34 +0200 Subject: [PATCH 04/12] Update files to reflect the api change --- js/app/controllers/credential.js | 70 ++++++++++++++++---------------- js/app/controllers/settings.js | 4 +- js/app/controllers/vault.js | 4 +- js/templates.js | 10 ++++- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index 33e6615a..ec0e5623 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -27,6 +27,42 @@ angular.module('passmanApp') } + + $scope.show_spinner = true; + + + var fetchCredentials = function () { + VaultService.getVault($scope.active_vault).then(function (vault) { + $scope.active_vault = angular.merge($scope.active_vault, vault); + var _credentials = []; + for (var i = 0; i < $scope.active_vault.credentials.length; i++) { + try { + $scope.active_vault.credentials[i] = CredentialService.decryptCredential(angular.copy(vault.credentials[i])); + } catch (e) { + NotificationService.showNotification('An error happend during decryption', 5000); + $rootScope.$broadcast('logout'); + SettingsService.setSetting('defaultVaultPass', null); + SettingsService.setSetting('defaultVault', null); + $location.path('/') + + } + if ($scope.active_vault.credentials[i]) { + TagService.addTags($scope.active_vault.credentials[i].tags); + + } + } + $scope.show_spinner = false; + + }); + }; + + if ($scope.active_vault) { + $scope.$parent.selectedVault = true; + fetchCredentials(); + } + + + $scope.addCredential = function () { var new_credential = CredentialService.newCredential(); var enc_c = CredentialService.encryptCredential(new_credential); @@ -201,40 +237,6 @@ angular.module('passmanApp') }); - $scope.show_spinner = true; - - - var fetchCredentials = function () { - VaultService.getVault($scope.active_vault).then(function (credentials) { - var _credentials = []; - for (var i = 0; i < credentials.length; i++) { - try { - var _c = CredentialService.decryptCredential(angular.copy(credentials[i])); - } catch (e) { - NotificationService.showNotification('An error happend during decryption', 5000); - $rootScope.$broadcast('logout'); - SettingsService.setSetting('defaultVaultPass', null); - SettingsService.setSetting('defaultVault', null); - $location.path('/') - - } - if (_c) { - _c.tags_raw = _c.tags; - TagService.addTags(_c.tags); - _credentials.push(_c); - } - } - $scope.credentials = _credentials; - $scope.show_spinner = false; - - }); - }; - - if ($scope.active_vault) { - $scope.$parent.selectedVault = true; - fetchCredentials(); - } - $scope.downloadFile = function (file) { FileService.getFile(file).then(function (result) { diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index dc5d8247..b6d0924b 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -85,9 +85,9 @@ angular.module('passmanApp') }); $scope.startScan = function (minStrength) { - VaultService.getVault($scope.active_vault).then(function (credentials) { + VaultService.getVault($scope.active_vault).then(function (vault) { var results = []; - for (var i = 0; i < credentials.length; i++) { + for (var i = 0; i < vault.credentials.length; i++) { var c = CredentialService.decryptCredential(angular.copy(credentials[i])); if (c.password && c.password.length > 0 && c.hidden == 0) { var zxcvbn_result = zxcvbn(c.password); diff --git a/js/app/controllers/vault.js b/js/app/controllers/vault.js index 0acb69c7..6b0d44fe 100644 --- a/js/app/controllers/vault.js +++ b/js/app/controllers/vault.js @@ -99,8 +99,8 @@ angular.module('passmanApp') var _vault = angular.copy(vault); _vault.vaultKey = angular.copy(vault_key); VaultService.setActiveVault(_vault); - VaultService.getVault(vault).then(function (credentials) { - var credential = credentials[0]; + VaultService.getVault(vault).then(function (vault) { + var credential = vault.credentials[0]; try { var c = CredentialService.decryptCredential(credential); if ($scope.remember_vault_password) { diff --git a/js/templates.js b/js/templates.js index 9ae56e76..f68ffa77 100644 --- a/js/templates.js +++ b/js/templates.js @@ -1,4 +1,4 @@ -angular.module('templates-main', ['views/credential_revisions.html', 'views/edit_credential.html', 'views/partials/forms/edit_credential/basics.html', 'views/partials/forms/edit_credential/custom_fields.html', 'views/partials/forms/edit_credential/files.html', 'views/partials/forms/edit_credential/otp.html', 'views/partials/forms/edit_credential/password.html', 'views/partials/forms/settings/export.html', 'views/partials/forms/settings/general_settings.html', 'views/partials/forms/settings/import.html', 'views/partials/forms/settings/sharing.html', 'views/partials/forms/settings/tool.html', 'views/partials/forms/share_credential/basics.html', 'views/partials/forms/share_credential/expire_settings.html', 'views/partials/password-meter.html', 'views/settings.html', 'views/share_credential.html', 'views/show_vault.html', 'views/vaults.html']); +angular.module('templates-main', ['views/credential_revisions.html', 'views/edit_credential.html', 'views/partials/forms/edit_credential/basics.html', 'views/partials/forms/edit_credential/custom_fields.html', 'views/partials/forms/edit_credential/files.html', 'views/partials/forms/edit_credential/otp.html', 'views/partials/forms/edit_credential/password.html', 'views/partials/forms/settings/export.html', 'views/partials/forms/settings/general_settings.html', 'views/partials/forms/settings/import.html', 'views/partials/forms/settings/password_settings.html', 'views/partials/forms/settings/sharing.html', 'views/partials/forms/settings/tool.html', 'views/partials/forms/share_credential/basics.html', 'views/partials/forms/share_credential/expire_settings.html', 'views/partials/password-meter.html', 'views/settings.html', 'views/share_credential.html', 'views/show_vault.html', 'views/vaults.html']); angular.module('views/credential_revisions.html', []).run(['$templateCache', function($templateCache) { 'use strict'; @@ -60,6 +60,12 @@ angular.module('views/partials/forms/settings/import.html', []).run(['$templateC '
{{selectedImporter.description}}

Read progress
{{ file_read_progress.loaded }} / {{ file_read_progress.total }}
Upload progress
{{ import_progress.loaded }} / {{ import_progress.total }}
'); }]); +angular.module('views/partials/forms/settings/password_settings.html', []).run(['$templateCache', function($templateCache) { + 'use strict'; + $templateCache.put('views/partials/forms/settings/password_settings.html', + '
'); +}]); + angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/sharing.html', @@ -107,7 +113,7 @@ angular.module('views/share_credential.html', []).run(['$templateCache', functio angular.module('views/show_vault.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/show_vault.html', - '
Showing deleted since: All time {{delete_time | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
+
{{credential.label}} {{tag.text}}
  • {{credential.label}}
    {{tag.text}}
Label{{selectedCredential.label}}
Account
Password
OTP
E-mail
URL
Files
{{field.label}}
Expire time{{selectedCredential.expire_time * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
Changed{{selectedCredential.changed * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
Created{{selectedCredential.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
{{tag.text}}
'); + '
Showing deleted since: All time {{delete_time | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
+
{{credential.label}} {{tag.text}}
  • {{credential.label}}
    {{tag.text}}
Label{{selectedCredential.label}}
Account
Password
OTP
E-mail
URL
Files
{{field.label}}
Expire time{{selectedCredential.expire_time * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
Changed{{selectedCredential.changed * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
Created{{selectedCredential.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
{{tag.text}}
'); }]); angular.module('views/vaults.html', []).run(['$templateCache', function($templateCache) { From d2b8902838f5fbc4e8dbcba57ccde80ce4189fa5 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 20:29:07 +0200 Subject: [PATCH 05/12] Use the new variable for the credentials --- templates/views/show_vault.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/views/show_vault.html b/templates/views/show_vault.html index 0fad02df..e90e52bc 100644 --- a/templates/views/show_vault.html +++ b/templates/views/show_vault.html @@ -61,7 +61,7 @@
- @@ -76,7 +76,7 @@
    -
  • From 30213a8fd2a166702f327349505180e63717c44a Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 20:29:50 +0200 Subject: [PATCH 06/12] Add getById --- lib/Service/VaultService.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Service/VaultService.php b/lib/Service/VaultService.php index 26916b05..d078674b 100644 --- a/lib/Service/VaultService.php +++ b/lib/Service/VaultService.php @@ -29,12 +29,29 @@ class VaultService { return $this->vaultMapper->findVaultsFromUser($userId); } + public function getById($vault_id, $user_id) { + $vault = $this->vaultMapper->find($vault_id, $user_id); + $vault = $vault[0]; + $return = array( + 'vault_id' => $vault->getId(), + 'guid' => $vault->getGuid(), + 'name' => $vault->getName(), + 'created' => $vault->getCreated(), + 'private_sharing_key' => $vault->getPrivateSharingKey(), + 'public_sharing_key' => $vault->getPublicSharingKey(), + 'sharing_keys_generated' => $vault->getSharingKeysGenerated(), + 'settings' => $vault->getSettings(), + 'last_access' => $vault->getlastAccess() + ); + return $return; + } + public function createVault($vault_name, $userId) { return $this->vaultMapper->create($vault_name, $userId); } - public function setLastAccess($vault_id){ - return $this->vaultMapper->setLastAccess($vault_id); + public function setLastAccess($vault_id, $user_id){ + return $this->vaultMapper->setLastAccess($vault_id, $user_id); } public function updateSharingKeys($vault_id, $privateKey, $publicKey){ From 9df4e53856cb1166e1719a278c38149a897a8e8a Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 21:05:29 +0200 Subject: [PATCH 07/12] Add tags_raw --- js/app/controllers/credential.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index ec0e5623..bbf7b111 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -38,6 +38,7 @@ angular.module('passmanApp') for (var i = 0; i < $scope.active_vault.credentials.length; i++) { try { $scope.active_vault.credentials[i] = CredentialService.decryptCredential(angular.copy(vault.credentials[i])); + $scope.active_vault.credentials[i].tags_raw = $scope.active_vault.credentials[i].tags; } catch (e) { NotificationService.showNotification('An error happend during decryption', 5000); $rootScope.$broadcast('logout'); @@ -52,7 +53,6 @@ angular.module('passmanApp') } } $scope.show_spinner = false; - }); }; From ab07f2b9bd6e8436c929ab8b091c935c0bfa9064 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 21:21:58 +0200 Subject: [PATCH 08/12] Use patch --- js/app/services/vaultservice.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/js/app/services/vaultservice.js b/js/app/services/vaultservice.js index b546a71d..284c69e9 100644 --- a/js/app/services/vaultservice.js +++ b/js/app/services/vaultservice.js @@ -23,13 +23,6 @@ angular.module('passmanApp') }); }, setActiveVault: function(vault){ - this.getVaults().then(function(vaults){ - for(var v = 0; v < vaults.length; v++){ - if(vaults[v].vault_id == vault.vault_id){ - _activeVault = angular.merge(_activeVault, vaults[v]); - } - } - }); _activeVault = vault; }, getActiveVault: function(vault){ @@ -56,8 +49,12 @@ angular.module('passmanApp') }); }, updateVault: function (vault) { + var _vault = angular.copy(vault); + delete vault.defaultVaultPass; + delete vault.defaultVault; + var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id); - return $http.post(queryUrl).then(function (response) { + return $http.patch(queryUrl).then(function (response) { if(response.data){ return response.data; } else { From bc1650556e24e6e555f6ffe58c49b0c007751ce3 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 21:22:49 +0200 Subject: [PATCH 09/12] Move response format to controller --- controller/vaultcontroller.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php index 5c920546..bccbf1c2 100644 --- a/controller/vaultcontroller.php +++ b/controller/vaultcontroller.php @@ -56,9 +56,25 @@ class VaultController extends ApiController { */ public function get($vault_id) { $credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId); - $result = $this->vaultService->getById($vault_id, $this->userId); - $result['credentials'] = $credentials; - $this->vaultService->setLastAccess($vault_id, $this->userId); + $vault = $this->vaultService->getById($vault_id, $this->userId); + $vault = $vault[0]; + if($vault) { + $result = array( + 'vault_id' => $vault->getId(), + 'guid' => $vault->getGuid(), + 'name' => $vault->getName(), + 'created' => $vault->getCreated(), + 'private_sharing_key' => $vault->getPrivateSharingKey(), + 'public_sharing_key' => $vault->getPublicSharingKey(), + 'sharing_keys_generated' => $vault->getSharingKeysGenerated(), + 'settings' => $vault->getSettings(), + 'last_access' => $vault->getlastAccess() + ); + $result['credentials'] = $credentials; + $this->vaultService->setLastAccess($vault_id, $this->userId); + } else { + $result = array(); + } return new JSONResponse($result); } @@ -66,7 +82,8 @@ class VaultController extends ApiController { * @NoAdminRequired */ public function update($vault_id) { - return; + $this->vaultService->getById($vault_id, $this->userId); + } /** From 8920a36ea769d9b90d88a8b950d329612fd254fa Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 22:05:09 +0200 Subject: [PATCH 10/12] Save work --- appinfo/database.xml | 2 +- appinfo/info.xml | 2 +- controller/vaultcontroller.php | 14 +++-- js/app/controllers/settings.js | 58 +++++++++++++++++-- js/app/services/encryptservice.js | 3 +- js/app/services/vaultservice.js | 7 ++- js/templates.js | 2 +- lib/Db/Vault.php | 6 +- lib/Db/VaultMapper.php | 4 ++ lib/Service/VaultService.php | 18 ++---- .../forms/settings/password_settings.html | 52 +++++++++++++++++ 11 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 templates/views/partials/forms/settings/password_settings.html diff --git a/appinfo/database.xml b/appinfo/database.xml index 6901f66b..8837da82 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -37,7 +37,7 @@ true - settings + vault_settings clob false diff --git a/appinfo/info.xml b/appinfo/info.xml index bcd27f37..bf63a5a1 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ A password manager for Nextcloud AGPL Sander Brand - 1.0.2.10 + 1.0.2.11 Passman other https://github.com/nextcloud/passman/ diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php index bccbf1c2..d6009b18 100644 --- a/controller/vaultcontroller.php +++ b/controller/vaultcontroller.php @@ -67,7 +67,7 @@ class VaultController extends ApiController { 'private_sharing_key' => $vault->getPrivateSharingKey(), 'public_sharing_key' => $vault->getPublicSharingKey(), 'sharing_keys_generated' => $vault->getSharingKeysGenerated(), - 'settings' => $vault->getSettings(), + 'vault_settings' => $vault->getVaultSettings(), 'last_access' => $vault->getlastAccess() ); $result['credentials'] = $credentials; @@ -81,9 +81,15 @@ class VaultController extends ApiController { /** * @NoAdminRequired */ - public function update($vault_id) { - $this->vaultService->getById($vault_id, $this->userId); - + public function update($vault_id, $name, $vault_settings) { + $vault = array_pop($this->vaultService->getById($vault_id, $this->userId)); + if($name) { + $vault->setName($name); + } + if($vault_settings) { + $vault->setVaultSettings($vault_settings); + } + $this->vaultService->updateVault($vault); } /** diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index b6d0924b..848d612f 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -8,9 +8,51 @@ * Controller of the passmanApp */ angular.module('passmanApp') - .controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', - function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http) { - $scope.active_vault = VaultService.getActiveVault(); + .controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', 'EncryptService', + function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http, EncryptService) { + + 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')); + VaultService.setActiveVault(_vault); + $scope.active_vault = _vault; + + } + } + + var _settings = { + pwSettings: { + 'length': 12, + 'useUppercase': true, + 'useLowercase': true, + 'useDigits': true, + 'useSpecialChars': true, + 'minimumDigitCount': 3, + 'avoidAmbiguousCharacters': false, + 'requireEveryCharType': true + } + }; + + $scope.vault_settings = angular.merge(_settings, $scope.active_vault.vault_settings); + console.log($scope.vault_settings); + + + $scope.saveVaultSettings = function () { + var _vault = $scope.active_vault; + _vault.vault_settings = angular.copy($scope.vault_settings); + _vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings)); + VaultService.updateVault(_vault).then(function () { + console.log('done'); + }); + }; + + + + $scope.tabs = [ { title: 'General settings', @@ -20,6 +62,11 @@ angular.module('passmanApp') title: 'Password Audit', url: 'views/partials/forms/settings/tool.html' + }, + { + title: 'Password settings', + url: 'views/partials/forms/settings/password_settings.html' + }, { title: 'Import credentials', @@ -33,7 +80,7 @@ angular.module('passmanApp') }, { title: 'Sharing', - url:'views/partials/forms/settings/sharing.html' + url: 'views/partials/forms/settings/sharing.html' } ]; @@ -58,7 +105,7 @@ angular.module('passmanApp') $scope.$watch(function () { return VaultService.getActiveVault() }, function (vault) { - if(vault) { + if (vault) { $scope.active_vault = vault; } }); @@ -108,7 +155,6 @@ angular.module('passmanApp') $scope.cancel = function () { $location.path('/vault/' + $routeParams.vault_id); - }; }]); diff --git a/js/app/services/encryptservice.js b/js/app/services/encryptservice.js index 4c67cec9..2b35ec0d 100644 --- a/js/app/services/encryptservice.js +++ b/js/app/services/encryptservice.js @@ -34,6 +34,7 @@ angular.module('passmanApp') } catch(e) { throw e; } - } + }, + } }]); diff --git a/js/app/services/vaultservice.js b/js/app/services/vaultservice.js index 284c69e9..6d61fc65 100644 --- a/js/app/services/vaultservice.js +++ b/js/app/services/vaultservice.js @@ -42,6 +42,9 @@ angular.module('passmanApp') var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id); return $http.get(queryUrl).then(function (response) { if(response.data){ + if(response.data.vault_settings){ + response.data.vault_settings = JSON.parse(window.atob(response.data.vault_settings)) + } return response.data; } else { return response; @@ -53,8 +56,8 @@ angular.module('passmanApp') delete vault.defaultVaultPass; delete vault.defaultVault; - var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id); - return $http.patch(queryUrl).then(function (response) { + var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + _vault.vault_id); + return $http.patch(queryUrl, _vault).then(function (response) { if(response.data){ return response.data; } else { diff --git a/js/templates.js b/js/templates.js index f68ffa77..30759abf 100644 --- a/js/templates.js +++ b/js/templates.js @@ -63,7 +63,7 @@ angular.module('views/partials/forms/settings/import.html', []).run(['$templateC angular.module('views/partials/forms/settings/password_settings.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/password_settings.html', - '
    '); + '
    '); }]); angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) { diff --git a/lib/Db/Vault.php b/lib/Db/Vault.php index ca312290..c840cdea 100644 --- a/lib/Db/Vault.php +++ b/lib/Db/Vault.php @@ -31,8 +31,8 @@ use \OCP\AppFramework\Db\Entity; * @method string getPrivateSharingKey() * @method void setSharingKeysGenerated(integer $value) * @method integer getSharingKeysGenerated() - * @method void setSettings(integer $value) - * @method integer getSettings() + * @method void setVaultSettings(integer $value) + * @method integer getVaultSettings() */ @@ -48,7 +48,7 @@ class Vault extends Entity implements \JsonSerializable{ protected $publicSharingKey; protected $privateSharingKey; protected $sharingKeysGenerated; - protected $settings; + protected $vaultSettings; public function __construct() { // add types in constructor diff --git a/lib/Db/VaultMapper.php b/lib/Db/VaultMapper.php index 0c7e3d6d..b804a054 100644 --- a/lib/Db/VaultMapper.php +++ b/lib/Db/VaultMapper.php @@ -58,6 +58,10 @@ class VaultMapper extends Mapper { $this->update($vault); } + public function updateVault(Vault $vault){ + $this->update($vault); + } + public function updateSharingKeys($vault_id, $privateKey, $publicKey){ $vault = new Vault(); $vault->setId($vault_id); diff --git a/lib/Service/VaultService.php b/lib/Service/VaultService.php index d078674b..a8b365c4 100644 --- a/lib/Service/VaultService.php +++ b/lib/Service/VaultService.php @@ -31,25 +31,17 @@ class VaultService { public function getById($vault_id, $user_id) { $vault = $this->vaultMapper->find($vault_id, $user_id); - $vault = $vault[0]; - $return = array( - 'vault_id' => $vault->getId(), - 'guid' => $vault->getGuid(), - 'name' => $vault->getName(), - 'created' => $vault->getCreated(), - 'private_sharing_key' => $vault->getPrivateSharingKey(), - 'public_sharing_key' => $vault->getPublicSharingKey(), - 'sharing_keys_generated' => $vault->getSharingKeysGenerated(), - 'settings' => $vault->getSettings(), - 'last_access' => $vault->getlastAccess() - ); - return $return; + return $vault; } public function createVault($vault_name, $userId) { return $this->vaultMapper->create($vault_name, $userId); } + public function updateVault($vault) { + return $this->vaultMapper->updateVault($vault); + } + public function setLastAccess($vault_id, $user_id){ return $this->vaultMapper->setLastAccess($vault_id, $user_id); } diff --git a/templates/views/partials/forms/settings/password_settings.html b/templates/views/partials/forms/settings/password_settings.html new file mode 100644 index 00000000..c04e6529 --- /dev/null +++ b/templates/views/partials/forms/settings/password_settings.html @@ -0,0 +1,52 @@ +
    +
    + + +
    +
    + + + + + + +
    +
    +
    +
    + +
    +
    \ No newline at end of file From 3394d78d369e1bb0f9feaffe9e6eda5996100a4e Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 28 Sep 2016 22:15:03 +0200 Subject: [PATCH 11/12] Save work --- js/app/controllers/edit_credential.js | 25 +++++++++++-------- js/app/controllers/settings.js | 5 ++-- js/app/services/vaultservice.js | 8 ++++++ js/templates.js | 2 +- .../forms/settings/password_settings.html | 5 ++++ 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index cf08a249..887bcb75 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -34,17 +34,22 @@ angular.module('passmanApp') url: 'views/partials/forms/edit_credential/otp.html', color: 'purple' }]; + if($scope.active_vault.vault_settings && $scope.active_vault.vault_settings.pwSettings){ + $scope.pwSettings = angular.copy($scope.active_vault.vault_settings.pwSettings); + } else { + $scope.pwSettings = { + 'length': 12, + 'useUppercase': true, + 'useLowercase': true, + 'useDigits': true, + 'useSpecialChars': true, + 'minimumDigitCount': 3, + 'avoidAmbiguousCharacters': false, + 'requireEveryCharType': true, + 'generateOnCreate': true, + }; + } - $scope.pwSettings = { - 'length': 12, - 'useUppercase': true, - 'useLowercase': true, - 'useDigits': true, - 'useSpecialChars': true, - 'minimumDigitCount': 3, - 'avoidAmbiguousCharacters': false, - 'requireEveryCharType': true - }; if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) { if (!$scope.active_vault) { diff --git a/js/app/controllers/settings.js b/js/app/controllers/settings.js index 848d612f..2abafb17 100644 --- a/js/app/controllers/settings.js +++ b/js/app/controllers/settings.js @@ -33,7 +33,8 @@ angular.module('passmanApp') 'useSpecialChars': true, 'minimumDigitCount': 3, 'avoidAmbiguousCharacters': false, - 'requireEveryCharType': true + 'requireEveryCharType': true, + 'generateOnCreate': true, } }; @@ -46,7 +47,7 @@ angular.module('passmanApp') _vault.vault_settings = angular.copy($scope.vault_settings); _vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings)); VaultService.updateVault(_vault).then(function () { - console.log('done'); + VaultService.setActiveVault(_vault); }); }; diff --git a/js/app/services/vaultservice.js b/js/app/services/vaultservice.js index 6d61fc65..e3174757 100644 --- a/js/app/services/vaultservice.js +++ b/js/app/services/vaultservice.js @@ -28,6 +28,14 @@ angular.module('passmanApp') getActiveVault: function(vault){ return _activeVault; }, + getVaultSetting: function(key, default_value){ + if(!_activeVault.vault_settings){ + return default_value + } else { + return _activeVault.vault_settings[key] | default_value; + } + + }, createVault: function (vaultName) { var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults'); return $http.post(queryUrl, { vault_name: vaultName }).then(function (response) { diff --git a/js/templates.js b/js/templates.js index 30759abf..c359f422 100644 --- a/js/templates.js +++ b/js/templates.js @@ -63,7 +63,7 @@ angular.module('views/partials/forms/settings/import.html', []).run(['$templateC angular.module('views/partials/forms/settings/password_settings.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/password_settings.html', - '
    '); + '
    '); }]); angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) { diff --git a/templates/views/partials/forms/settings/password_settings.html b/templates/views/partials/forms/settings/password_settings.html index c04e6529..8666fb35 100644 --- a/templates/views/partials/forms/settings/password_settings.html +++ b/templates/views/partials/forms/settings/password_settings.html @@ -10,6 +10,11 @@ +