passman/controller/internalcontroller.php

73 lines
1.9 KiB
PHP
Raw Normal View History

2016-09-24 00:17:47 +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;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCA\Passman\Service\CredentialService;
2016-09-25 02:47:47 +08:00
use \OC_App;
2016-09-24 00:17:47 +08:00
class InternalController extends ApiController {
private $userId;
private $credentialService;
2016-09-25 02:47:47 +08:00
2016-09-24 00:17:47 +08:00
public function __construct($AppName,
IRequest $request,
$UserId,
2016-09-25 02:47:47 +08:00
CredentialService $credentialService) {
2016-09-24 00:17:47 +08:00
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->credentialService = $credentialService;
}
2016-09-25 02:47:47 +08:00
/**
* @NoAdminRequired
*/
public function remind($credential_id) {
2016-09-24 00:17:47 +08:00
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
2016-09-25 02:47:47 +08:00
$credential->setExpireTime(time() + (24 * 60 * 60));
2016-09-24 00:17:47 +08:00
$this->credentialService->upd($credential);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
}
2016-09-25 02:47:47 +08:00
/**
* @NoAdminRequired
*/
public function read($credential_id) {
2016-09-24 00:17:47 +08:00
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
$credential->setExpireTime(0);
$this->credentialService->upd($credential);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
}
2016-09-25 02:47:47 +08:00
/**
* @NoAdminRequired
*/
public function getAppVersion() {
return new JSONResponse(array('version' => OC_App::getAppVersion('passman')));
}
2016-09-24 00:17:47 +08:00
}