1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @author Christoph Wurst <[email protected]> |
8
|
|
|
* @author Roeland Jago Douma <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\Settings\Settings\Personal\Security; |
28
|
|
|
|
29
|
|
|
use function array_filter; |
30
|
|
|
use function array_map; |
31
|
|
|
use function is_null; |
32
|
|
|
use OC\Authentication\TwoFactorAuth\ProviderLoader; |
33
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
34
|
|
|
use OCP\Authentication\TwoFactorAuth\IProvider; |
35
|
|
|
use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings; |
36
|
|
|
use OCP\IConfig; |
37
|
|
|
use OCP\IUserSession; |
38
|
|
|
use OCP\Settings\ISettings; |
39
|
|
|
|
40
|
|
|
class TwoFactor implements ISettings { |
41
|
|
|
|
42
|
|
|
/** @var ProviderLoader */ |
43
|
|
|
private $providerLoader; |
44
|
|
|
|
45
|
|
|
/** @var IUserSession */ |
46
|
|
|
private $userSession; |
47
|
|
|
|
48
|
|
|
/** @var string|null */ |
49
|
|
|
private $uid; |
50
|
|
|
|
51
|
|
|
/** @var IConfig */ |
52
|
|
|
private $config; |
53
|
|
|
|
54
|
|
|
public function __construct(ProviderLoader $providerLoader, |
55
|
|
|
IUserSession $userSession, |
56
|
|
|
IConfig $config, |
57
|
|
|
?string $UserId) { |
58
|
|
|
$this->providerLoader = $providerLoader; |
59
|
|
|
$this->userSession = $userSession; |
60
|
|
|
$this->uid = $UserId; |
61
|
|
|
$this->config = $config; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getForm(): TemplateResponse { |
65
|
|
|
return new TemplateResponse('settings', 'settings/personal/security/twofactor', [ |
66
|
|
|
'twoFactorProviderData' => $this->getTwoFactorProviderData(), |
67
|
|
|
'themedark' => $this->config->getUserValue($this->uid, 'accessibility', 'theme', false) |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getSection(): string { |
73
|
|
|
return 'security'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getPriority(): int { |
77
|
|
|
return 15; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function getTwoFactorProviderData(): array { |
81
|
|
|
$user = $this->userSession->getUser(); |
82
|
|
|
if (is_null($user)) { |
83
|
|
|
// Actually impossible, but still … |
84
|
|
|
return []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return [ |
88
|
|
|
'providers' => array_map(function (IProvidesPersonalSettings $provider) use ($user) { |
89
|
|
|
return [ |
90
|
|
|
'provider' => $provider, |
91
|
|
|
'settings' => $provider->getPersonalSettings($user) |
92
|
|
|
]; |
93
|
|
|
}, array_filter($this->providerLoader->getProviders($user), function (IProvider $provider) { |
94
|
|
|
return $provider instanceof IProvidesPersonalSettings; |
95
|
|
|
})) |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|