From d5f52180d072a4cf7eb8281f06f58891a5b3be0b Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 6 Jun 2022 23:27:08 +0530 Subject: [PATCH 1/2] Check for old accounts in userExists route --- lib/Controller/UserController.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 49748e2d..393e7f97 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -7,6 +7,7 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCP\IRequest; use OCP\ILogger; +use OCP\IConfig; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http\DataResponse; use OCA\EcloudAccounts\Service\UserService; @@ -22,12 +23,15 @@ class UserController extends ApiController private $logger; - public function __construct($appName, IRequest $request, ILogger $logger, UserService $userService, MailUsageMapper $mailUsageMapper) + private $config; + + 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; } /** @@ -43,7 +47,20 @@ class UserController extends ApiController return $response; } - $response->setData($this->userService->userExists($uid)); + $exists = false; + + if ($this->userService->userExists($uid)) { + $exists = true; + } + + // To check for old accounts + $mailDomain = $this->config->getSystemValue('mail_domain'); + $mailDomainSuffix = !empty($mailDomain) ? '@' . $mailDomain : ''; + if (stristr($uid, $mailDomainSuffix) === false) { + $exists = $this->userService->userExists($uid . $mailDomainSuffix); + } + + $response->setData($exists); return $response; } @@ -54,7 +71,6 @@ class UserController extends ApiController */ public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB'): DataResponse { - $response = new DataResponse(); if (!$this->checkAppCredentials($token)) { -- GitLab From 364bcc2f51e8973af0061889119d595d9295c982 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 7 Jun 2022 13:40:30 +0530 Subject: [PATCH 2/2] Correct old accounts check --- 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 393e7f97..8544f6bc 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -56,7 +56,7 @@ class UserController extends ApiController // To check for old accounts $mailDomain = $this->config->getSystemValue('mail_domain'); $mailDomainSuffix = !empty($mailDomain) ? '@' . $mailDomain : ''; - if (stristr($uid, $mailDomainSuffix) === false) { + if (!$exists && stristr($uid, $mailDomainSuffix) === false) { $exists = $this->userService->userExists($uid . $mailDomainSuffix); } -- GitLab