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

internalcontroller.php « controller - github.com/nextcloud/passman.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: defab3dec56ead2c8ce8b3457b9ce54ddc75b5e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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;


class InternalController extends ApiController {
	private $userId;
	private $credentialService;

	public function __construct($AppName,
								IRequest $request,
								$UserId,
								CredentialService $credentialService) {
		parent::__construct($AppName, $request);
		$this->userId = $UserId;
		$this->credentialService = $credentialService;
	}

	/**
	 * @NoAdminRequired
	 */
	public function remind($credential_id) {
		$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
		$credential->setExpireTime(time() + (24 * 60 * 60));
		$this->credentialService->upd($credential);

		$manager = \OC::$server->getNotificationManager();
		$notification = $manager->createNotification();
		$notification->setApp('passman')
			->setObject('credential', $credential_id)
			->setUser($this->userId);
		$manager->markProcessed($notification);
	}

	/**
	 * @NoAdminRequired
	 */
	public function read($credential_id) {

		$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);
	}

	/**
	 * @NoAdminRequired
	 */
	public function getAppVersion() {
		return new JSONResponse(array('version' => '1.0.2.25'));
	}

	/**
	 * @NoAdminRequired
	 */
	public function generatePerson() {
		$random_person = json_decode(file_get_contents('http://api.namefake.com/'));
		return new JSONResponse($random_person);
	}

}