summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-10-03 09:56:21 +0200
committerGitHub <noreply@github.com>2018-10-03 09:56:21 +0200
commitf9e201adfea6974fd0b58ccb4596bcaee4cf41dd (patch)
treedd4420e87ec99ce0609137ac748c683c2436940e /lib/private
parent8ede3f6346aaf96671878b320b82fd5542acef91 (diff)
parentdaa897100e0b3aea8d4a85890dfa64852c7f5d5f (diff)
downloadnextcloud-server-f9e201adfea6974fd0b58ccb4596bcaee4cf41dd.tar.gz
nextcloud-server-f9e201adfea6974fd0b58ccb4596bcaee4cf41dd.zip
Merge pull request #11409 from nextcloud/feature/consolidated-2fa-settings
Consolidate personal two-factor provider settings
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Settings/Personal/Security.php52
1 files changed, 48 insertions, 4 deletions
diff --git a/lib/private/Settings/Personal/Security.php b/lib/private/Settings/Personal/Security.php
index efcfd5589ce..0efe2d0746b 100644
--- a/lib/private/Settings/Personal/Security.php
+++ b/lib/private/Settings/Personal/Security.php
@@ -24,18 +24,41 @@
namespace OC\Settings\Personal;
+use function array_filter;
+use function array_map;
+use function is_null;
+use OC\Authentication\TwoFactorAuth\Manager as TwoFactorManager;
+use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Authentication\TwoFactorAuth\IProvider;
+use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Settings\ISettings;
class Security implements ISettings {
+ /** @var IUserManager */
private $userManager;
- public function __construct(
- IUserManager $userManager
- ) {
+ /** @var TwoFactorManager */
+ private $twoFactorManager;
+
+ /** @var ProviderLoader */
+ private $providerLoader;
+
+ /** @var IUserSession */
+ private $userSession;
+
+
+ public function __construct(IUserManager $userManager,
+ TwoFactorManager $providerManager,
+ ProviderLoader $providerLoader,
+ IUserSession $userSession) {
$this->userManager = $userManager;
+ $this->twoFactorManager = $providerManager;
+ $this->providerLoader = $providerLoader;
+ $this->userSession = $userSession;
}
/**
@@ -50,7 +73,8 @@ class Security implements ISettings {
}
return new TemplateResponse('settings', 'settings/personal/security', [
- 'passwordChangeSupported' => $passwordChangeSupported
+ 'passwordChangeSupported' => $passwordChangeSupported,
+ 'twoFactorProviderData' => $this->getTwoFactorProviderData(),
]);
}
@@ -73,4 +97,24 @@ class Security implements ISettings {
public function getPriority() {
return 10;
}
+
+ private function getTwoFactorProviderData(): array {
+ $user = $this->userSession->getUser();
+ if (is_null($user)) {
+ // Actually impossible, but still …
+ return [];
+ }
+
+ return [
+ 'isEnabled' => $this->twoFactorManager->isTwoFactorAuthenticated($user),
+ 'providers' => array_map(function (IProvidesPersonalSettings $provider) use ($user) {
+ return [
+ 'provider' => $provider,
+ 'settings' => $provider->getPersonalSettings($user)
+ ];
+ }, array_filter($this->providerLoader->getProviders($user), function (IProvider $provider) {
+ return $provider instanceof IProvidesPersonalSettings;
+ }))
+ ];
+ }
}