From 3ce8d758dd883cdd432a496efb155e24d7c37394 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Sep 2023 02:02:58 -0700 Subject: [PATCH 1/7] User Lanauge --- lib/Controller/UserController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 96bf75a3..caeb5cdc 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -12,6 +12,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; use OCP\ILogger; use OCP\IRequest; +use OCP\L10N\IFactory; class UserController extends ApiController { /** @var UserService */ @@ -22,13 +23,14 @@ class UserController extends ApiController { private $logger; private $config; - - public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper) { + protected $l10nFactory; + public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper, IFactory $l10nFactory) { parent::__construct($appName, $request); $this->userService = $userService; $this->mailUsageMapper = $mailUsageMapper; $this->logger = $logger; $this->config = $config; + $this->l10nFactory = $l10nFactory; } /** @@ -87,6 +89,13 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); + $userLanguage = 'es'; + if (in_array($userLanguage, $languagesCodes, true)) { + $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); + } else { + $this->logger->error('Invalid language '.$userLanguage); + } $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); -- GitLab From 2e6a46d44f126742e0c76b7ed6679e712ed56bf3 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Sep 2023 02:10:34 -0700 Subject: [PATCH 2/7] userLanguage en by default --- lib/Controller/UserController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index caeb5cdc..26650e31 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -67,7 +67,7 @@ class UserController extends ApiController { * @PublicPage * @NoCSRFRequired */ - public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false): DataResponse { + public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false, string $userLanguage = 'en'): DataResponse { $response = new DataResponse(); if (!$this->checkAppCredentials($token)) { @@ -90,7 +90,6 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); $languagesCodes = $this->l10nFactory->findAvailableLanguages(); - $userLanguage = 'es'; if (in_array($userLanguage, $languagesCodes, true)) { $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); } else { -- GitLab From 0703984ff3dd50c5db73285b18176b48e4d51ced Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Sep 2023 03:17:59 -0700 Subject: [PATCH 3/7] languageExists --- lib/Controller/UserController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 26650e31..0b46fa71 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -89,11 +89,8 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); - if (in_array($userLanguage, $languagesCodes, true)) { + if ($this->l10nFactory->languageExists('core', $userLanguage)) { $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); - } else { - $this->logger->error('Invalid language '.$userLanguage); } $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); -- GitLab From 0b1de4d6209ff6d8654a8a2e4bfeb4a1e9e7e68d Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Sep 2023 11:15:44 -0700 Subject: [PATCH 4/7] changed to null --- lib/Controller/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 0b46fa71..40aeae83 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -89,7 +89,7 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); - if ($this->l10nFactory->languageExists('core', $userLanguage)) { + if ($this->l10nFactory->languageExists(null, $userLanguage)) { $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); } $this->userService->sendWelcomeEmail($uid, $email); -- GitLab From 0e08ec07476e605e49d007492717e262d6cb2a10 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Sun, 24 Sep 2023 23:41:17 -0700 Subject: [PATCH 5/7] comment --- lib/Controller/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 40aeae83..1d0745d6 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -92,7 +92,7 @@ class UserController extends ApiController { if ($this->l10nFactory->languageExists(null, $userLanguage)) { $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); } - $this->userService->sendWelcomeEmail($uid, $email); + // $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); if (!$recoveryEmailUpdated) { -- GitLab From 2015551e6e4704462acd350e4239290a7aaf54e1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Sun, 24 Sep 2023 23:55:36 -0700 Subject: [PATCH 6/7] changes --- lib/Controller/UserController.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 1d0745d6..f859dd06 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -12,7 +12,6 @@ use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; use OCP\ILogger; use OCP\IRequest; -use OCP\L10N\IFactory; class UserController extends ApiController { /** @var UserService */ @@ -23,14 +22,13 @@ class UserController extends ApiController { private $logger; private $config; - protected $l10nFactory; - public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper, IFactory $l10nFactory) { + + public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper) { parent::__construct($appName, $request); $this->userService = $userService; $this->mailUsageMapper = $mailUsageMapper; $this->logger = $logger; $this->config = $config; - $this->l10nFactory = $l10nFactory; } /** @@ -67,7 +65,7 @@ class UserController extends ApiController { * @PublicPage * @NoCSRFRequired */ - public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false, string $userLanguage = 'en'): DataResponse { + public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false): DataResponse { $response = new DataResponse(); if (!$this->checkAppCredentials($token)) { @@ -89,9 +87,6 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); - if ($this->l10nFactory->languageExists(null, $userLanguage)) { - $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); - } // $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); -- GitLab From 111fa045ce1b841bc77c25d9fa1c6a0afd4c11bc Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 25 Sep 2023 01:22:08 -0700 Subject: [PATCH 7/7] back --- lib/Controller/UserController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index f859dd06..1d0745d6 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -12,6 +12,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; use OCP\ILogger; use OCP\IRequest; +use OCP\L10N\IFactory; class UserController extends ApiController { /** @var UserService */ @@ -22,13 +23,14 @@ class UserController extends ApiController { private $logger; private $config; - - public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper) { + protected $l10nFactory; + public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper, IFactory $l10nFactory) { parent::__construct($appName, $request); $this->userService = $userService; $this->mailUsageMapper = $mailUsageMapper; $this->logger = $logger; $this->config = $config; + $this->l10nFactory = $l10nFactory; } /** @@ -65,7 +67,7 @@ class UserController extends ApiController { * @PublicPage * @NoCSRFRequired */ - public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false): DataResponse { + public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false, string $userLanguage = 'en'): DataResponse { $response = new DataResponse(); if (!$this->checkAppCredentials($token)) { @@ -87,6 +89,9 @@ class UserController extends ApiController { $user->setEMailAddress($email); $user->setQuota($quota); + if ($this->l10nFactory->languageExists(null, $userLanguage)) { + $this->config->setUserValue($uid, 'core', 'lang', $userLanguage); + } // $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); -- GitLab