Passed
Push — master ( b39fb5...590849 )
by Roeland
11:59 queued 10s
created

WebAuthn::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 8
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\Settings\Settings\Personal\Security;
26
27
use OC\Authentication\WebAuthn\Db\PublicKeyCredentialMapper;
28
use OC\Authentication\WebAuthn\Manager;
29
use OCA\Settings\AppInfo\Application;
30
use OCP\AppFramework\Http\TemplateResponse;
31
use OCP\IInitialStateService;
32
use OCP\Settings\ISettings;
33
34
class WebAuthn implements ISettings {
35
36
	/** @var PublicKeyCredentialMapper */
37
	private $mapper;
38
39
	/** @var string */
40
	private $uid;
41
42
	/** @var IInitialStateService */
43
	private $initialStateService;
44
45
	/** @var Manager */
46
	private $manager;
47
48
	public function __construct(PublicKeyCredentialMapper $mapper,
49
								string $UserId,
50
								IInitialStateService $initialStateService,
51
								Manager $manager) {
52
		$this->mapper = $mapper;
53
		$this->uid = $UserId;
54
		$this->initialStateService = $initialStateService;
55
		$this->manager = $manager;
56
	}
57
58
	public function getForm() {
59
		$this->initialStateService->provideInitialState(
60
			Application::APP_ID,
61
			'webauthn-devices',
62
			$this->mapper->findAllForUid($this->uid)
63
		);
64
65
		return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
66
		]);
67
	}
68
69
	public function getSection(): ?string {
70
		if (!$this->manager->isWebAuthnAvailable()) {
71
			return null;
72
		}
73
74
		return 'security';
75
	}
76
77
	public function getPriority(): int {
78
		return 20;
79
	}
80
}
81