From 9f6e782796f4138cf217003f4c9276c79d177d34 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 15 Sep 2023 11:30:32 -0700 Subject: [PATCH 1/4] temp logger --- lib/Controller/UserController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 96bf75a3..6ddb8a99 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -67,13 +67,15 @@ class UserController extends ApiController { */ public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false): DataResponse { $response = new DataResponse(); - + $this->logger->error('API CALLED. UID:'.$uid); if (!$this->checkAppCredentials($token)) { + $this->logger->error('checkAppCredentials Failed'); $response->setStatus(401); return $response; } if (!$this->userService->userExists($uid)) { + $this->logger->error('userExists Failed'); $response->setStatus(404); return $response; } @@ -82,11 +84,14 @@ class UserController extends ApiController { if (is_null($user)) { $response->setStatus(404); + $this->logger->error('user not found'); return $response; } - + $this->logger->error('Setting Email address :'.$email); $user->setEMailAddress($email); + $this->logger->error('Setting quota :'.$quota); $user->setQuota($quota); + $this->logger->error('Sending email...'); $this->userService->sendWelcomeEmail($uid, $email); $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); -- GitLab From 2efa658a012d25f03c31af870d04920df80f3eb9 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 15 Sep 2023 11:32:46 -0700 Subject: [PATCH 2/4] logger changes --- lib/Controller/UserController.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 6ddb8a99..0582ec88 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -67,41 +67,49 @@ class UserController extends ApiController { */ public function setAccountData(string $token, string $uid, string $email, string $recoveryEmail, string $hmeAlias, string $quota = '1024 MB', bool $tosAccepted = false): DataResponse { $response = new DataResponse(); - $this->logger->error('API CALLED. UID:'.$uid); + $this->logger->info('API CALLED. UID: ' . $uid); + if (!$this->checkAppCredentials($token)) { $this->logger->error('checkAppCredentials Failed'); $response->setStatus(401); return $response; } - + if (!$this->userService->userExists($uid)) { $this->logger->error('userExists Failed'); $response->setStatus(404); return $response; } - + $user = $this->userService->getUser($uid); - + if (is_null($user)) { $response->setStatus(404); - $this->logger->error('user not found'); + $this->logger->error('User not found'); return $response; } - $this->logger->error('Setting Email address :'.$email); + + $this->logger->info('Setting Email address: ' . $email); $user->setEMailAddress($email); - $this->logger->error('Setting quota :'.$quota); + + $this->logger->info('Setting quota: ' . $quota); $user->setQuota($quota); - $this->logger->error('Sending email...'); + + $this->logger->info('Sending welcome email...'); $this->userService->sendWelcomeEmail($uid, $email); + $this->config->setUserValue($uid, 'terms_of_service', 'tosAccepted', intval($tosAccepted)); + $recoveryEmailUpdated = $this->userService->setRecoveryEmail($uid, $recoveryEmail); if (!$recoveryEmailUpdated) { return $this->getErrorResponse($response, 'error_setting_recovery', 400); } + $hmeAliasAdded = $this->userService->addHMEAliasInConfig($uid, $hmeAlias); if (!$hmeAliasAdded) { return $this->getErrorResponse($response, 'error_adding_hme_alias', 400); } + return $response; } -- GitLab From 9bf13865ac16a3d87e7bf966ee9fe0d6551730c0 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 15 Sep 2023 11:34:59 -0700 Subject: [PATCH 3/4] psr logger --- lib/Controller/UserController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 0582ec88..2b9be93b 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Controller; +use \Psr\Log\LoggerInterface; use Exception; use OCA\EcloudAccounts\Db\MailUsageMapper; use OCA\EcloudAccounts\Service\UserService; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; -use OCP\ILogger; use OCP\IRequest; class UserController extends ApiController { @@ -23,7 +23,7 @@ class UserController extends ApiController { private $config; - public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper) { + public function __construct($appName, IRequest $request, LoggerInterface $logger, IConfig $config, UserService $userService, MailUsageMapper $mailUsageMapper) { parent::__construct($appName, $request); $this->userService = $userService; $this->mailUsageMapper = $mailUsageMapper; -- GitLab From c3e4797b0d51e2524a9a2da2be976e4b1d32ce5e Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 15 Sep 2023 12:08:10 -0700 Subject: [PATCH 4/4] psr logger --- lib/Controller/UserController.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Controller/UserController.php b/lib/Controller/UserController.php index 2b9be93b..dd71cf83 100644 --- a/lib/Controller/UserController.php +++ b/lib/Controller/UserController.php @@ -70,13 +70,25 @@ class UserController extends ApiController { $this->logger->info('API CALLED. UID: ' . $uid); if (!$this->checkAppCredentials($token)) { - $this->logger->error('checkAppCredentials Failed'); + $this->logger->error('checkAppCredentials Failed token:'.$token); + $response->setData(['error' => 'checkAppCredentials Failed token:'.$token]); $response->setStatus(401); return $response; } - - if (!$this->userService->userExists($uid)) { + + $exists = false; + if ($this->userService->userExists($uid)) { + $exists = true; + } + // To check for old accounts + $legacyDomain = $this->config->getSystemValue('legacy_domain'); + $legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : ''; + if (!$exists && stristr($uid, $legacyDomainSuffix) === false) { + $exists = $this->userService->userExists($uid . $legacyDomainSuffix); + } + if (!$exists) { $this->logger->error('userExists Failed'); + $response->setData(['error' => 'userExists Failed UID: '.$uid]); $response->setStatus(404); return $response; } @@ -85,6 +97,7 @@ class UserController extends ApiController { if (is_null($user)) { $response->setStatus(404); + $response->setData(['error' => 'User not found']); $this->logger->error('User not found'); return $response; } -- GitLab