2019-05-03 09:09:19 -04:00
|
|
|
<?php
|
2021-06-04 15:52:51 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2019-05-03 09:09:19 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-05-03 09:09:19 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Authentication\Login;
|
|
|
|
|
|
2025-08-18 05:59:49 -04:00
|
|
|
use OC\Core\AppInfo\Application;
|
|
|
|
|
use OC\Core\AppInfo\ConfigLexicon;
|
2019-05-03 09:09:19 -04:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\ISession;
|
|
|
|
|
|
|
|
|
|
class SetUserTimezoneCommand extends ALoginCommand {
|
|
|
|
|
/** @var IConfig */
|
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
|
|
/** @var ISession */
|
|
|
|
|
private $session;
|
|
|
|
|
|
|
|
|
|
public function __construct(IConfig $config,
|
|
|
|
|
ISession $session) {
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->session = $session;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function process(LoginData $loginData): LoginResult {
|
2023-01-04 11:52:02 -05:00
|
|
|
if ($loginData->getTimeZoneOffset() !== '' && $this->isValidTimezone($loginData->getTimeZone())) {
|
2025-08-18 05:59:49 -04:00
|
|
|
$userId = $loginData->getUser()->getUID();
|
|
|
|
|
if ($this->config->getUserValue($userId, Application::APP_ID, ConfigLexicon::USER_TIMEZONE, '') === '') {
|
|
|
|
|
$this->config->setUserValue($userId, Application::APP_ID, ConfigLexicon::USER_TIMEZONE, $loginData->getTimeZone());
|
|
|
|
|
}
|
2019-05-03 09:09:19 -04:00
|
|
|
$this->session->set(
|
|
|
|
|
'timezone',
|
|
|
|
|
$loginData->getTimeZoneOffset()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->processNextOrFinishSuccessfully($loginData);
|
|
|
|
|
}
|
2023-01-04 11:52:02 -05:00
|
|
|
|
|
|
|
|
private function isValidTimezone(?string $value): bool {
|
|
|
|
|
return $value && in_array($value, \DateTimeZone::listIdentifiers());
|
|
|
|
|
}
|
2019-05-03 09:09:19 -04:00
|
|
|
}
|