Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/passman.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrantje <brantje@gmail.com>2017-01-12 01:55:28 +0300
committerbrantje <brantje@gmail.com>2017-01-12 02:17:23 +0300
commita8ae7e0bdaf9c88a05df4f7de26292baa7c03736 (patch)
tree8de1e153e1ae70e74f971a18768bdccd090d3b3f /controller
parentabe26ea906badd13c896147f29b87f8575e9fed0 (diff)
Implement delete vault
Diffstat (limited to 'controller')
-rw-r--r--controller/credentialcontroller.php33
-rw-r--r--controller/translationcontroller.php6
-rw-r--r--controller/vaultcontroller.php27
3 files changed, 44 insertions, 22 deletions
diff --git a/controller/credentialcontroller.php b/controller/credentialcontroller.php
index e956a131..554755e7 100644
--- a/controller/credentialcontroller.php
+++ b/controller/credentialcontroller.php
@@ -11,10 +11,12 @@
namespace OCA\Passman\Controller;
+use OCA\Passman\Db\Credential;
use OCA\Passman\Db\SharingACL;
use OCA\Passman\Service\EncryptService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Utility\NotFoundJSONResponse;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
@@ -241,7 +243,7 @@ class CredentialController extends ApiController {
$credential['shared_key'] = '';
}
- if(!isset($credential['shared_key'])){
+ if (!isset($credential['shared_key'])) {
$credential['shared_key'] = $storedCredential->getSharedKey();
}
@@ -259,23 +261,34 @@ class CredentialController extends ApiController {
* @NoCSRFRequired
*/
public function deleteCredential($credential_guid) {
- $credential = $this->credentialService->getCredentialByGUID($credential_guid, $this->userId);
+ try {
+ $credential = $this->credentialService->getCredentialByGUID($credential_guid, $this->userId);
+ } catch (\Exception $e) {
+ return new NotFoundJSONResponse();
+ }
if ($credential) {
$result = $this->credentialService->deleteCredential($credential);
- $this->activityService->add(
- 'item_destroyed_self', array($credential->getLabel()),
- '', array(),
- '', $this->userId, Activity::TYPE_ITEM_ACTION);
- $this->sharingService->unshareCredential($credential->getGuid());
- foreach($this->credentialRevisionService->getRevisions($credential->getId()) as $revision){
- $this->credentialRevisionService->deleteRevision($revision->getId(), $this->userId);
- }
+ $this->deleteCredentialParts($credential);
} else {
$result = false;
}
return new JSONResponse($result);
}
+ /**
+ * Delete leftovers from a credential
+ * @param Credential $credential
+ */
+ private function deleteCredentialParts(Credential $credential) {
+ $this->activityService->add(
+ 'item_destroyed_self', array($credential->getLabel()),
+ '', array(),
+ '', $this->userId, Activity::TYPE_ITEM_ACTION);
+ $this->sharingService->unshareCredential($credential->getGuid());
+ foreach ($this->credentialRevisionService->getRevisions($credential->getId()) as $revision) {
+ $this->credentialRevisionService->deleteRevision($revision->getId(), $this->userId);
+ }
+ }
/**
* @NoAdminRequired
diff --git a/controller/translationcontroller.php b/controller/translationcontroller.php
index a944c887..4bfcabf8 100644
--- a/controller/translationcontroller.php
+++ b/controller/translationcontroller.php
@@ -186,6 +186,12 @@ class TranslationController extends ApiController {
'bookmarklet' => $this->trans->t('Bookmarklet'),
'bookmarklet.info1' => $this->trans->t('Save your passwords with 1 click!'),
'bookmarklet.info2' => $this->trans->t('Drag below button to your bookmark toolbar.'),
+ 'delete.vault' => $this->trans->t('Delete vault'),
+ 'vault.password' => $this->trans->t('Vault password'),
+ 'vault.remove.notice' => $this->trans->t('This process is irreversible'),
+ 'delete.vault.checkbox' => $this->trans->t('Delete my precious passwords'),
+ 'deleting.pw' => $this->trans->t('Deleting {{password}}...'),
+ 'delete.vault.confirm' => $this->trans->t('Yes, delete my precious passwords'),
// templates/views/partials/forms/settings/import.html
diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php
index cec3e485..8381dd63 100644
--- a/controller/vaultcontroller.php
+++ b/controller/vaultcontroller.php
@@ -55,19 +55,21 @@ class VaultController extends ApiController {
$vaults = $this->vaultService->getByUser($this->userId);
$protected_credential_fields = array('getDescription', 'getEmail', 'getUsername', 'getPassword');
- if ($vaults) {
+ if (isset($vaults)) {
foreach ($vaults as $vault) {
$credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId);
$secret_field = $protected_credential_fields[array_rand($protected_credential_fields)];
- array_push($result, array(
- 'vault_id' => $vault->getId(),
- 'guid' => $vault->getGuid(),
- 'name' => $vault->getName(),
- 'created' => $vault->getCreated(),
- 'public_sharing_key' => $vault->getPublicSharingKey(),
- 'last_access' => $vault->getlastAccess(),
- 'challenge_password' => $credential->{$secret_field}(),
- ));
+ if(isset($credential)) {
+ array_push($result, array(
+ 'vault_id' => $vault->getId(),
+ 'guid' => $vault->getGuid(),
+ 'name' => $vault->getName(),
+ 'created' => $vault->getCreated(),
+ 'public_sharing_key' => $vault->getPublicSharingKey(),
+ 'last_access' => $vault->getlastAccess(),
+ 'challenge_password' => $credential->{$secret_field}(),
+ ));
+ }
}
}
@@ -95,7 +97,7 @@ class VaultController extends ApiController {
return new NotFoundJSONResponse();
}
$result = array();
- if ($vault) {
+ if (isset($vault)) {
$credentials = $this->credentialService->getCredentialsByVaultId($vault->getId(), $this->userId);
$result = array(
@@ -157,6 +159,7 @@ class VaultController extends ApiController {
* @NoCSRFRequired
*/
public function delete($vault_id) {
- return new JSONResponse($vault_id);
+ $this->vaultService->deleteVault($vault_id, $this->userId);
+ return new JSONResponse(array('ok' => true));
}
} \ No newline at end of file