From 442dc6e2b5cfa5a098575ce087eb005734acc021 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 27 Aug 2025 18:36:21 +0530 Subject: [PATCH 1/2] Add user to common data store immediately after registration at LDAP --- lib/Controller/AccountController.php | 9 ++------- lib/Service/UserService.php | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index b8e8c037..1b13b764 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -8,7 +8,6 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCA\EcloudAccounts\AppInfo\Application; -use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCA\EcloudAccounts\Exception\RecoveryEmailValidationException; use OCA\EcloudAccounts\Service\CaptchaService; @@ -190,6 +189,8 @@ class AccountController extends Controller { $userEmail = $username.'@'.$mainDomain; $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password, $language); sleep(5); + $ipAddress = $this->request->getRemoteAddress(); + $this->userService->addUsernameToCommonDataStore($username, $ipAddress, $recoveryEmail); $this->userService->setAccountDataLocally($username, $userEmail); $this->userService->createHMEAlias($username, $userEmail); @@ -207,8 +208,6 @@ class AccountController extends Controller { $this->session->remove(self::SESSION_VERIFIED_USERNAME); $this->session->remove(self::SESSION_VERIFIED_DISPLAYNAME); $this->session->remove(self::CAPTCHA_VERIFIED_CHECK); - $ipAddress = $this->request->getRemoteAddress(); - $this->userService->addUsernameToCommonDataStore($username, $ipAddress, $recoveryEmail); $response->setStatus(200); $response->setData(['success' => true]); @@ -221,10 +220,6 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => $e->getMessage(), 'success' => false]); $response->setStatus(400); - } catch (AddUsernameToCommonStoreException $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); - $response->setStatus(200); - $response->setData(['success' => true]); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'An error occurred while creating your account!', 'success' => false]); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 04966466..1952a9b6 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -472,7 +472,10 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - throw new AddUsernameToCommonStoreException("Error adding username '$username' to common data store."); + $this->logger->logException( + new AddUsernameToCommonStoreException("Error adding username '$username' to common data store."), + ['app' => Application::APP_ID] + ); } } -- GitLab From c55c01fea14180eefcbfe632afb5f650ad49cafb Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 27 Aug 2025 18:45:47 +0530 Subject: [PATCH 2/2] nested try-catch instead of no exception --- lib/Controller/AccountController.php | 11 ++++++++--- lib/Service/UserService.php | 5 +---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 1b13b764..589c0db5 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -189,9 +189,14 @@ class AccountController extends Controller { $userEmail = $username.'@'.$mainDomain; $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password, $language); sleep(5); - $ipAddress = $this->request->getRemoteAddress(); - $this->userService->addUsernameToCommonDataStore($username, $ipAddress, $recoveryEmail); - + try { + // Don't want this operation to block the rest of registration logic + // so we need a nested try-catch + $ipAddress = $this->request->getRemoteAddress(); + $this->userService->addUsernameToCommonDataStore($username, $ipAddress, $recoveryEmail); + } catch (\Throwable $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + } $this->userService->setAccountDataLocally($username, $userEmail); $this->userService->createHMEAlias($username, $userEmail); $this->userService->createNewDomainAlias($username, $userEmail); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 1952a9b6..04966466 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -472,10 +472,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - $this->logger->logException( - new AddUsernameToCommonStoreException("Error adding username '$username' to common data store."), - ['app' => Application::APP_ID] - ); + throw new AddUsernameToCommonStoreException("Error adding username '$username' to common data store."); } } -- GitLab