-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSettingsController.php
More file actions
82 lines (69 loc) · 2 KB
/
SettingsController.php
File metadata and controls
82 lines (69 loc) · 2 KB
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
82
<?php
declare(strict_types = 1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorWebauthn\Controller;
use OCA\TwoFactorWebauthn\Service\WebAuthnManager;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
use OCP\IRequest;
use OCP\IUserSession;
class SettingsController extends ALoginSetupController {
/** @var WebAuthnManager */
private $manager;
/** @var IUserSession */
private $userSession;
public function __construct(string $appName, IRequest $request, WebAuthnManager $manager, IUserSession $userSession) {
parent::__construct($appName, $request);
$this->manager = $manager;
$this->userSession = $userSession;
}
/**
* @NoAdminRequired
* @PasswordConfirmationRequired
* @UseSession
*/
public function startRegister(): JSONResponse {
$user = $this->userSession->getUser();
$options = $this->manager->startRegistration($user, $this->request->getServerHost());
$data = json_decode(json_encode($options), true);
if (isset($data['user']['displayName'])) {
$data['user']['displayName'] = $user->getUID();
}
return new JSONResponse($data);
}
/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @param string $name
* @param string $data
*/
public function finishRegister(string $name, string $data): JSONResponse {
return new JSONResponse(
$this->manager->finishRegister(
$this->userSession->getUser(),
$name,
$data
)
);
}
/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*/
public function remove(int $id): JSONResponse {
$this->manager->removeDevice($this->userSession->getUser(), $id);
return new JSONResponse([]);
}
/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*/
public function changeActivationState(int $id, bool $active): JSONResponse {
$this->manager->changeActivationState($this->userSession->getUser(), $id, $active);
return new JSONResponse([]);
}
}