@@ -46,143 +46,143 @@ |
||
| 46 | 46 | |
| 47 | 47 | class Security implements ISettings { |
| 48 | 48 | |
| 49 | - /** @var IUserManager */ |
|
| 50 | - private $userManager; |
|
| 51 | - |
|
| 52 | - /** @var TwoFactorManager */ |
|
| 53 | - private $twoFactorManager; |
|
| 54 | - |
|
| 55 | - /** @var IAuthTokenProvider */ |
|
| 56 | - private $tokenProvider; |
|
| 57 | - |
|
| 58 | - /** @var ProviderLoader */ |
|
| 59 | - private $providerLoader; |
|
| 60 | - |
|
| 61 | - /** @var IUserSession */ |
|
| 62 | - private $userSession; |
|
| 63 | - |
|
| 64 | - /** @var ISession */ |
|
| 65 | - private $session; |
|
| 66 | - |
|
| 67 | - /** @var IInitialStateService */ |
|
| 68 | - private $initialStateService; |
|
| 69 | - /** |
|
| 70 | - * @var string|null |
|
| 71 | - */ |
|
| 72 | - private $uid; |
|
| 73 | - /** |
|
| 74 | - *@var IConfig |
|
| 75 | - */ |
|
| 76 | - private $config; |
|
| 77 | - |
|
| 78 | - public function __construct(IUserManager $userManager, |
|
| 79 | - TwoFactorManager $providerManager, |
|
| 80 | - IAuthTokenProvider $tokenProvider, |
|
| 81 | - ProviderLoader $providerLoader, |
|
| 82 | - IUserSession $userSession, |
|
| 83 | - ISession $session, |
|
| 84 | - IConfig $config, |
|
| 85 | - IInitialStateService $initialStateService, |
|
| 86 | - ?string $UserId) { |
|
| 87 | - $this->userManager = $userManager; |
|
| 88 | - $this->twoFactorManager = $providerManager; |
|
| 89 | - $this->tokenProvider = $tokenProvider; |
|
| 90 | - $this->providerLoader = $providerLoader; |
|
| 91 | - $this->userSession = $userSession; |
|
| 92 | - $this->session = $session; |
|
| 93 | - $this->initialStateService = $initialStateService; |
|
| 94 | - $this->uid = $UserId; |
|
| 95 | - $this->config = $config; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 100 | - * @since 9.1 |
|
| 101 | - */ |
|
| 102 | - public function getForm() { |
|
| 103 | - $user = $this->userManager->get($this->uid); |
|
| 104 | - $passwordChangeSupported = false; |
|
| 105 | - if ($user !== null) { |
|
| 106 | - $passwordChangeSupported = $user->canChangePassword(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->initialStateService->provideInitialState( |
|
| 110 | - 'settings', |
|
| 111 | - 'app_tokens', |
|
| 112 | - $this->getAppTokens() |
|
| 113 | - ); |
|
| 114 | - |
|
| 115 | - return new TemplateResponse('settings', 'settings/personal/security', [ |
|
| 116 | - 'passwordChangeSupported' => $passwordChangeSupported, |
|
| 117 | - 'twoFactorProviderData' => $this->getTwoFactorProviderData(), |
|
| 118 | - 'themedark' => $this->config->getUserValue($this->uid, 'accessibility', 'theme', false) |
|
| 119 | - ]); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return string the section ID, e.g. 'sharing' |
|
| 124 | - * @since 9.1 |
|
| 125 | - */ |
|
| 126 | - public function getSection() { |
|
| 127 | - return 'security'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return int whether the form should be rather on the top or bottom of |
|
| 132 | - * the admin section. The forms are arranged in ascending order of the |
|
| 133 | - * priority values. It is required to return a value between 0 and 100. |
|
| 134 | - * |
|
| 135 | - * E.g.: 70 |
|
| 136 | - * @since 9.1 |
|
| 137 | - */ |
|
| 138 | - public function getPriority() { |
|
| 139 | - return 10; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - private function getTwoFactorProviderData(): array { |
|
| 143 | - $user = $this->userSession->getUser(); |
|
| 144 | - if (is_null($user)) { |
|
| 145 | - // Actually impossible, but still … |
|
| 146 | - return []; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return [ |
|
| 150 | - 'providers' => array_map(function (IProvidesPersonalSettings $provider) use ($user) { |
|
| 151 | - return [ |
|
| 152 | - 'provider' => $provider, |
|
| 153 | - 'settings' => $provider->getPersonalSettings($user) |
|
| 154 | - ]; |
|
| 155 | - }, array_filter($this->providerLoader->getProviders($user), function (IProvider $provider) { |
|
| 156 | - return $provider instanceof IProvidesPersonalSettings; |
|
| 157 | - })) |
|
| 158 | - ]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - private function getAppTokens(): array { |
|
| 162 | - $tokens = $this->tokenProvider->getTokenByUser($this->uid); |
|
| 163 | - |
|
| 164 | - try { |
|
| 165 | - $sessionId = $this->session->getId(); |
|
| 166 | - } catch (SessionNotAvailableException $ex) { |
|
| 167 | - return []; |
|
| 168 | - } |
|
| 169 | - try { |
|
| 170 | - $sessionToken = $this->tokenProvider->getToken($sessionId); |
|
| 171 | - } catch (InvalidTokenException $ex) { |
|
| 172 | - return []; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return array_map(function (IToken $token) use ($sessionToken) { |
|
| 176 | - $data = $token->jsonSerialize(); |
|
| 177 | - $data['canDelete'] = true; |
|
| 178 | - $data['canRename'] = $token instanceof INamedToken; |
|
| 179 | - if ($sessionToken->getId() === $token->getId()) { |
|
| 180 | - $data['canDelete'] = false; |
|
| 181 | - $data['canRename'] = false; |
|
| 182 | - $data['current'] = true; |
|
| 183 | - } |
|
| 184 | - return $data; |
|
| 185 | - }, $tokens); |
|
| 186 | - } |
|
| 49 | + /** @var IUserManager */ |
|
| 50 | + private $userManager; |
|
| 51 | + |
|
| 52 | + /** @var TwoFactorManager */ |
|
| 53 | + private $twoFactorManager; |
|
| 54 | + |
|
| 55 | + /** @var IAuthTokenProvider */ |
|
| 56 | + private $tokenProvider; |
|
| 57 | + |
|
| 58 | + /** @var ProviderLoader */ |
|
| 59 | + private $providerLoader; |
|
| 60 | + |
|
| 61 | + /** @var IUserSession */ |
|
| 62 | + private $userSession; |
|
| 63 | + |
|
| 64 | + /** @var ISession */ |
|
| 65 | + private $session; |
|
| 66 | + |
|
| 67 | + /** @var IInitialStateService */ |
|
| 68 | + private $initialStateService; |
|
| 69 | + /** |
|
| 70 | + * @var string|null |
|
| 71 | + */ |
|
| 72 | + private $uid; |
|
| 73 | + /** |
|
| 74 | + *@var IConfig |
|
| 75 | + */ |
|
| 76 | + private $config; |
|
| 77 | + |
|
| 78 | + public function __construct(IUserManager $userManager, |
|
| 79 | + TwoFactorManager $providerManager, |
|
| 80 | + IAuthTokenProvider $tokenProvider, |
|
| 81 | + ProviderLoader $providerLoader, |
|
| 82 | + IUserSession $userSession, |
|
| 83 | + ISession $session, |
|
| 84 | + IConfig $config, |
|
| 85 | + IInitialStateService $initialStateService, |
|
| 86 | + ?string $UserId) { |
|
| 87 | + $this->userManager = $userManager; |
|
| 88 | + $this->twoFactorManager = $providerManager; |
|
| 89 | + $this->tokenProvider = $tokenProvider; |
|
| 90 | + $this->providerLoader = $providerLoader; |
|
| 91 | + $this->userSession = $userSession; |
|
| 92 | + $this->session = $session; |
|
| 93 | + $this->initialStateService = $initialStateService; |
|
| 94 | + $this->uid = $UserId; |
|
| 95 | + $this->config = $config; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 100 | + * @since 9.1 |
|
| 101 | + */ |
|
| 102 | + public function getForm() { |
|
| 103 | + $user = $this->userManager->get($this->uid); |
|
| 104 | + $passwordChangeSupported = false; |
|
| 105 | + if ($user !== null) { |
|
| 106 | + $passwordChangeSupported = $user->canChangePassword(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->initialStateService->provideInitialState( |
|
| 110 | + 'settings', |
|
| 111 | + 'app_tokens', |
|
| 112 | + $this->getAppTokens() |
|
| 113 | + ); |
|
| 114 | + |
|
| 115 | + return new TemplateResponse('settings', 'settings/personal/security', [ |
|
| 116 | + 'passwordChangeSupported' => $passwordChangeSupported, |
|
| 117 | + 'twoFactorProviderData' => $this->getTwoFactorProviderData(), |
|
| 118 | + 'themedark' => $this->config->getUserValue($this->uid, 'accessibility', 'theme', false) |
|
| 119 | + ]); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return string the section ID, e.g. 'sharing' |
|
| 124 | + * @since 9.1 |
|
| 125 | + */ |
|
| 126 | + public function getSection() { |
|
| 127 | + return 'security'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return int whether the form should be rather on the top or bottom of |
|
| 132 | + * the admin section. The forms are arranged in ascending order of the |
|
| 133 | + * priority values. It is required to return a value between 0 and 100. |
|
| 134 | + * |
|
| 135 | + * E.g.: 70 |
|
| 136 | + * @since 9.1 |
|
| 137 | + */ |
|
| 138 | + public function getPriority() { |
|
| 139 | + return 10; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + private function getTwoFactorProviderData(): array { |
|
| 143 | + $user = $this->userSession->getUser(); |
|
| 144 | + if (is_null($user)) { |
|
| 145 | + // Actually impossible, but still … |
|
| 146 | + return []; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return [ |
|
| 150 | + 'providers' => array_map(function (IProvidesPersonalSettings $provider) use ($user) { |
|
| 151 | + return [ |
|
| 152 | + 'provider' => $provider, |
|
| 153 | + 'settings' => $provider->getPersonalSettings($user) |
|
| 154 | + ]; |
|
| 155 | + }, array_filter($this->providerLoader->getProviders($user), function (IProvider $provider) { |
|
| 156 | + return $provider instanceof IProvidesPersonalSettings; |
|
| 157 | + })) |
|
| 158 | + ]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + private function getAppTokens(): array { |
|
| 162 | + $tokens = $this->tokenProvider->getTokenByUser($this->uid); |
|
| 163 | + |
|
| 164 | + try { |
|
| 165 | + $sessionId = $this->session->getId(); |
|
| 166 | + } catch (SessionNotAvailableException $ex) { |
|
| 167 | + return []; |
|
| 168 | + } |
|
| 169 | + try { |
|
| 170 | + $sessionToken = $this->tokenProvider->getToken($sessionId); |
|
| 171 | + } catch (InvalidTokenException $ex) { |
|
| 172 | + return []; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return array_map(function (IToken $token) use ($sessionToken) { |
|
| 176 | + $data = $token->jsonSerialize(); |
|
| 177 | + $data['canDelete'] = true; |
|
| 178 | + $data['canRename'] = $token instanceof INamedToken; |
|
| 179 | + if ($sessionToken->getId() === $token->getId()) { |
|
| 180 | + $data['canDelete'] = false; |
|
| 181 | + $data['canRename'] = false; |
|
| 182 | + $data['current'] = true; |
|
| 183 | + } |
|
| 184 | + return $data; |
|
| 185 | + }, $tokens); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | } |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | script('settings', [ |
| 25 | - 'templates', |
|
| 26 | - 'vue-settings-personal-security', |
|
| 25 | + 'templates', |
|
| 26 | + 'vue-settings-personal-security', |
|
| 27 | 27 | ]); |
| 28 | 28 | |
| 29 | 29 | if($_['passwordChangeSupported']) { |
| 30 | - script('settings', 'security_password'); |
|
| 30 | + script('settings', 'security_password'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | ?> |
@@ -70,29 +70,29 @@ discard block |
||
| 70 | 70 | <li> |
| 71 | 71 | <?php |
| 72 | 72 | |
| 73 | - /** @var \OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings $provider */ |
|
| 74 | - $provider = $data['provider']; |
|
| 75 | - //Handle 2FA provider icons and theme |
|
| 76 | - if ($provider instanceof \OCP\Authentication\TwoFactorAuth\IProvidesIcons) { |
|
| 77 | - if ($_['themedark']) { |
|
| 78 | - $icon = $provider->getLightIcon(); |
|
| 79 | - } |
|
| 80 | - else { |
|
| 81 | - $icon = $provider->getDarkIcon(); |
|
| 82 | - } |
|
| 83 | - //fallback icon if the 2factor provider doesn't provide an icon. |
|
| 84 | - } else { |
|
| 85 | - if ($_['themedark']) { |
|
| 86 | - $icon = image_path('core', 'actions/password-white.svg'); |
|
| 87 | - } |
|
| 88 | - else { |
|
| 89 | - $icon = image_path('core', 'actions/password.svg'); |
|
| 90 | - } |
|
| 73 | + /** @var \OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings $provider */ |
|
| 74 | + $provider = $data['provider']; |
|
| 75 | + //Handle 2FA provider icons and theme |
|
| 76 | + if ($provider instanceof \OCP\Authentication\TwoFactorAuth\IProvidesIcons) { |
|
| 77 | + if ($_['themedark']) { |
|
| 78 | + $icon = $provider->getLightIcon(); |
|
| 79 | + } |
|
| 80 | + else { |
|
| 81 | + $icon = $provider->getDarkIcon(); |
|
| 82 | + } |
|
| 83 | + //fallback icon if the 2factor provider doesn't provide an icon. |
|
| 84 | + } else { |
|
| 85 | + if ($_['themedark']) { |
|
| 86 | + $icon = image_path('core', 'actions/password-white.svg'); |
|
| 87 | + } |
|
| 88 | + else { |
|
| 89 | + $icon = image_path('core', 'actions/password.svg'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - } |
|
| 93 | - /** @var \OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings $settings */ |
|
| 94 | - $settings = $data['settings']; |
|
| 95 | - ?> |
|
| 92 | + } |
|
| 93 | + /** @var \OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings $settings */ |
|
| 94 | + $settings = $data['settings']; |
|
| 95 | + ?> |
|
| 96 | 96 | <h3> |
| 97 | 97 | <img class="two-factor-provider-settings-icon" src="<?php p($icon) ?>" alt=""> |
| 98 | 98 | <?php p($provider->getDisplayName()) ?> |
@@ -76,16 +76,14 @@ |
||
| 76 | 76 | if ($provider instanceof \OCP\Authentication\TwoFactorAuth\IProvidesIcons) { |
| 77 | 77 | if ($_['themedark']) { |
| 78 | 78 | $icon = $provider->getLightIcon(); |
| 79 | - } |
|
| 80 | - else { |
|
| 79 | + } else { |
|
| 81 | 80 | $icon = $provider->getDarkIcon(); |
| 82 | 81 | } |
| 83 | 82 | //fallback icon if the 2factor provider doesn't provide an icon. |
| 84 | 83 | } else { |
| 85 | 84 | if ($_['themedark']) { |
| 86 | 85 | $icon = image_path('core', 'actions/password-white.svg'); |
| 87 | - } |
|
| 88 | - else { |
|
| 86 | + } else { |
|
| 89 | 87 | $icon = image_path('core', 'actions/password.svg'); |
| 90 | 88 | } |
| 91 | 89 | |