2017-05-17 14:41:20 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author Greta Doci <gretadoci@gmail.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-05-17 14:41:20 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-05-17 14:41:20 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
namespace OCA\Settings\Personal;
|
2017-05-17 14:41:20 +03:00
|
|
|
|
|
|
|
|
2018-09-26 17:25:18 +03:00
|
|
|
use function array_filter;
|
|
|
|
use function array_map;
|
|
|
|
use function is_null;
|
2019-03-01 16:09:54 +03:00
|
|
|
use OC\Authentication\Exceptions\InvalidTokenException;
|
|
|
|
use OC\Authentication\Token\INamedToken;
|
|
|
|
use OC\Authentication\Token\IProvider as IAuthTokenProvider;
|
|
|
|
use OC\Authentication\Token\IToken;
|
2018-09-26 17:25:18 +03:00
|
|
|
use OC\Authentication\TwoFactorAuth\Manager as TwoFactorManager;
|
|
|
|
use OC\Authentication\TwoFactorAuth\ProviderLoader;
|
2017-05-17 14:41:20 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2018-09-26 17:25:18 +03:00
|
|
|
use OCP\Authentication\TwoFactorAuth\IProvider;
|
|
|
|
use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IConfig;
|
2019-03-01 16:09:54 +03:00
|
|
|
use OCP\IInitialStateService;
|
|
|
|
use OCP\ISession;
|
2018-06-29 14:01:22 +03:00
|
|
|
use OCP\IUserManager;
|
2018-09-26 17:25:18 +03:00
|
|
|
use OCP\IUserSession;
|
2019-03-01 16:09:54 +03:00
|
|
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
2017-05-17 14:41:20 +03:00
|
|
|
use OCP\Settings\ISettings;
|
|
|
|
|
2017-06-16 16:34:16 +03:00
|
|
|
class Security implements ISettings {
|
2017-05-17 14:41:20 +03:00
|
|
|
|
2019-09-12 16:40:21 +03:00
|
|
|
/** @var IInitialStateService */
|
|
|
|
private $initialStateService;
|
|
|
|
|
2018-09-26 17:25:18 +03:00
|
|
|
/** @var IUserManager */
|
2018-06-29 14:01:22 +03:00
|
|
|
private $userManager;
|
|
|
|
|
2018-09-26 17:25:18 +03:00
|
|
|
/** @var ProviderLoader */
|
|
|
|
private $providerLoader;
|
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
|
2019-09-09 23:12:29 +03:00
|
|
|
/** @var string|null */
|
2019-03-01 16:09:54 +03:00
|
|
|
private $uid;
|
2019-09-09 23:12:29 +03:00
|
|
|
|
|
|
|
/** @var IConfig */
|
2019-05-17 14:00:08 +03:00
|
|
|
private $config;
|
2018-09-26 17:25:18 +03:00
|
|
|
|
2019-09-12 16:40:21 +03:00
|
|
|
public function __construct(IInitialStateService $initialStateService,
|
|
|
|
IUserManager $userManager,
|
2018-09-26 17:25:18 +03:00
|
|
|
ProviderLoader $providerLoader,
|
2019-03-01 16:09:54 +03:00
|
|
|
IUserSession $userSession,
|
2019-05-17 14:00:08 +03:00
|
|
|
IConfig $config,
|
2019-03-01 16:09:54 +03:00
|
|
|
?string $UserId) {
|
2019-09-12 16:40:21 +03:00
|
|
|
$this->initialStateService = $initialStateService;
|
2018-06-29 14:01:22 +03:00
|
|
|
$this->userManager = $userManager;
|
2018-09-26 17:25:18 +03:00
|
|
|
$this->providerLoader = $providerLoader;
|
|
|
|
$this->userSession = $userSession;
|
2019-03-01 16:09:54 +03:00
|
|
|
$this->uid = $UserId;
|
2019-05-17 14:00:08 +03:00
|
|
|
$this->config = $config;
|
2018-06-29 14:01:22 +03:00
|
|
|
}
|
|
|
|
|
2019-09-09 23:12:29 +03:00
|
|
|
public function getForm(): TemplateResponse {
|
2019-03-01 16:09:54 +03:00
|
|
|
$user = $this->userManager->get($this->uid);
|
2018-06-29 14:01:22 +03:00
|
|
|
$passwordChangeSupported = false;
|
|
|
|
if ($user !== null) {
|
|
|
|
$passwordChangeSupported = $user->canChangePassword();
|
|
|
|
}
|
|
|
|
|
2019-06-12 15:26:01 +03:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
'settings',
|
|
|
|
'can_create_app_token',
|
2019-09-25 10:16:51 +03:00
|
|
|
$this->userSession->getImpersonatingUserID() === null
|
2019-06-12 15:26:01 +03:00
|
|
|
);
|
|
|
|
|
2018-06-29 14:01:22 +03:00
|
|
|
return new TemplateResponse('settings', 'settings/personal/security', [
|
2018-09-26 17:25:18 +03:00
|
|
|
'passwordChangeSupported' => $passwordChangeSupported,
|
|
|
|
'twoFactorProviderData' => $this->getTwoFactorProviderData(),
|
2019-05-17 14:00:08 +03:00
|
|
|
'themedark' => $this->config->getUserValue($this->uid, 'accessibility', 'theme', false)
|
2018-06-29 14:01:22 +03:00
|
|
|
]);
|
2019-06-12 15:26:01 +03:00
|
|
|
|
2017-05-17 14:41:20 +03:00
|
|
|
}
|
|
|
|
|
2019-09-09 23:12:29 +03:00
|
|
|
public function getSection(): string {
|
2017-06-16 16:34:16 +03:00
|
|
|
return 'security';
|
2017-05-17 14:41:20 +03:00
|
|
|
}
|
|
|
|
|
2019-09-09 23:12:29 +03:00
|
|
|
public function getPriority(): int {
|
2017-05-17 14:41:20 +03:00
|
|
|
return 10;
|
|
|
|
}
|
2018-09-26 17:25:18 +03:00
|
|
|
|
|
|
|
private function getTwoFactorProviderData(): array {
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if (is_null($user)) {
|
|
|
|
// Actually impossible, but still …
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'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;
|
|
|
|
}))
|
|
|
|
];
|
|
|
|
}
|
2017-05-17 14:41:20 +03:00
|
|
|
}
|