2016-09-09 23:36:35 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Nextcloud - passman
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Sander Brand <brantje@gmail.com>
|
|
|
|
* @copyright Sander Brand 2016
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Passman\Controller;
|
|
|
|
|
|
|
|
use OCP\IRequest;
|
2016-09-11 05:30:17 +08:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2016-09-10 00:02:53 +08:00
|
|
|
use OCP\AppFramework\ApiController;
|
2016-09-11 18:33:09 +08:00
|
|
|
use OCA\Passman\Service\VaultService;
|
2016-09-12 02:47:29 +08:00
|
|
|
use OCA\Passman\Service\CredentialService;
|
2016-09-12 01:45:20 +08:00
|
|
|
|
2016-09-15 00:57:38 +08:00
|
|
|
|
2016-09-10 00:02:53 +08:00
|
|
|
class VaultController extends ApiController {
|
2016-09-09 23:36:35 +08:00
|
|
|
private $userId;
|
2016-09-11 18:33:09 +08:00
|
|
|
private $vaultService;
|
2016-09-12 02:47:29 +08:00
|
|
|
private $credentialService;
|
2016-09-09 23:36:35 +08:00
|
|
|
|
2016-09-11 18:33:09 +08:00
|
|
|
public function __construct($AppName,
|
|
|
|
IRequest $request,
|
|
|
|
$UserId,
|
2016-09-12 02:47:29 +08:00
|
|
|
VaultService $vaultService,
|
|
|
|
CredentialService $credentialService) {
|
2016-09-09 23:36:35 +08:00
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->userId = $UserId;
|
2016-09-11 18:33:09 +08:00
|
|
|
$this->vaultService = $vaultService;
|
2016-09-12 02:47:29 +08:00
|
|
|
$this->credentialService = $credentialService;
|
2016-09-09 23:36:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-11 05:30:17 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function listVaults() {
|
|
|
|
|
2016-09-11 18:33:09 +08:00
|
|
|
$vaults = $this->vaultService->getByUser($this->userId);
|
2016-09-11 05:30:17 +08:00
|
|
|
return new JSONResponse($vaults);
|
|
|
|
}
|
|
|
|
|
2016-09-09 23:36:35 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2016-09-11 18:33:09 +08:00
|
|
|
public function create($vault_name) {
|
|
|
|
$vault = $this->vaultService->createVault($vault_name, $this->userId);
|
|
|
|
return new JSONResponse($vault);
|
2016-09-09 23:36:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2016-09-09 23:41:02 +08:00
|
|
|
public function get($vault_id) {
|
2016-09-12 02:47:29 +08:00
|
|
|
$credentials = $this->credentialService->getCredentialsByVaultId($vault_id, $this->userId);
|
2016-09-13 00:25:16 +08:00
|
|
|
$this->vaultService->setLastAccess($vault_id);
|
2016-09-12 02:47:29 +08:00
|
|
|
return new JSONResponse($credentials);
|
2016-09-09 23:36:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2016-09-09 23:41:02 +08:00
|
|
|
public function update($vault_id) {
|
2016-09-09 23:36:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-26 00:34:33 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function updateSharingKeys($vault_id, $private_sharing_key, $public_sharing_key) {
|
|
|
|
$this->vaultService->updateSharingKeys($vault_id, $private_sharing_key, $public_sharing_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-09 23:36:35 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2016-09-09 23:41:02 +08:00
|
|
|
public function delete($vault_id) {
|
2016-09-09 23:36:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|