Completed
Push — master ( 0fefb1...02ef01 )
by Marcos
02:32
created

InternalController::getAppVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Sander Brand <[email protected]>
9
 * @copyright Sander Brand 2016
10
 */
11
12
namespace OCA\Passman\Controller;
13
14
use OCP\IRequest;
15
use OCP\AppFramework\Http\JSONResponse;
16
use OCP\AppFramework\ApiController;
17
use OCA\Passman\Service\CredentialService;
18
19
20
class InternalController extends ApiController {
21
	private $userId;
22
	private $credentialService;
23
24
	public function __construct($AppName,
25
								IRequest $request,
26
								$UserId,
27
								CredentialService $credentialService) {
28
		parent::__construct($AppName, $request);
29
		$this->userId = $UserId;
30
		$this->credentialService = $credentialService;
31
	}
32
33
	/**
34
	 * @NoAdminRequired
35
	 */
36
	public function remind($credential_id) {
37
		$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
38
		$credential->setExpireTime(time() + (24 * 60 * 60));
39
		$this->credentialService->upd($credential);
40
41
		$manager = \OC::$server->getNotificationManager();
42
		$notification = $manager->createNotification();
43
		$notification->setApp('passman')
44
			->setObject('credential', $credential_id)
45
			->setUser($this->userId);
46
		$manager->markProcessed($notification);
47
	}
48
49
	/**
50
	 * @NoAdminRequired
51
	 */
52
	public function read($credential_id) {
53
54
		$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
55
		$credential->setExpireTime(0);
56
		$this->credentialService->upd($credential);
57
58
		$manager = \OC::$server->getNotificationManager();
59
		$notification = $manager->createNotification();
60
		$notification->setApp('passman')
61
			->setObject('credential', $credential_id)
62
			->setUser($this->userId);
63
		$manager->markProcessed($notification);
64
	}
65
66
	/**
67
	 * @NoAdminRequired
68
	 */
69
	public function getAppVersion() {
70
		return new JSONResponse(array('version' => '1.0.2.24'));
71
	}
72
73
	/**
74
	 * @NoAdminRequired
75
	 */
76 1
	public function generatePerson() {
77 1
		$random_person = json_decode(file_get_contents('http://api.namefake.com/'));
78 1
		return new JSONResponse($random_person);
79
	}
80
81
}