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

InternalController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 9.38%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 62
ccs 3
cts 32
cp 0.0938
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A remind() 0 12 1
A read() 0 13 1
A getAppVersion() 0 3 1
A generatePerson() 0 4 1
A __construct() 0 8 1
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
}