From 2ec9557120151d246e4461b07802b5f6de265602 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 18 Jun 2024 12:46:21 +0530 Subject: [PATCH 1/2] Added Validation Exception to show error message --- appinfo/info.xml | 2 +- lib/Controller/AccountController.php | 5 +++++ lib/Exception/RecoveryEmailValidationException.php | 9 +++++++++ lib/Service/UserService.php | 7 ++++--- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 lib/Exception/RecoveryEmailValidationException.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 9d095387..e6f7fd12 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 6.0.3 + 6.0.4 agpl Murena SAS EcloudAccounts diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 82aa8507..92289e84 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -11,6 +11,7 @@ use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; +use OCA\EcloudAccounts\Exception\RecoveryEmailValidationException; use OCA\EcloudAccounts\Service\CaptchaService; use OCA\EcloudAccounts\Service\NewsLetterService; use OCA\EcloudAccounts\Service\UserService; @@ -176,6 +177,10 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setStatus(200); $response->setData(['success' => true]); + } catch (RecoveryEmailValidationException | Error $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + $response->setData(['message' => $e->getMessage(), 'success' => false]); + $response->setStatus(500); } 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/Exception/RecoveryEmailValidationException.php b/lib/Exception/RecoveryEmailValidationException.php new file mode 100644 index 00000000..528a3372 --- /dev/null +++ b/lib/Exception/RecoveryEmailValidationException.php @@ -0,0 +1,9 @@ +isValidEmailFormat($recoveryEmail)) { - throw new Exception('Recovery email address has an incorrect format.'); + throw new RecoveryEmailValidationException('Recovery email address has an incorrect format.'); } if ($this->checkRecoveryEmailAvailable($recoveryEmail)) { - throw new Exception('Recovery email address is already taken.'); + throw new RecoveryEmailValidationException('Recovery email address is already taken.'); } if ($this->isRecoveryEmailDomainDisallowed($recoveryEmail)) { - throw new Exception('You cannot set an email address with a Murena domain as recovery email address.'); + throw new RecoveryEmailValidationException('You cannot set an email address with a Murena domain as recovery email address.'); } if ($this->isBlacklistedEmail($recoveryEmail)) { throw new BlacklistedEmailException('The domain of this email address is blacklisted. Please provide another recovery address.'); -- GitLab From 3aa370febcffe05a9363b4f2e5011cb94cfa8cf1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 18 Jun 2024 13:09:36 +0530 Subject: [PATCH 2/2] Added Validation Exception to show error message --- lib/Controller/AccountController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 92289e84..4b1421d1 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -169,7 +169,7 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); - } catch (BlacklistedEmailException | Error $e) { + } catch (BlacklistedEmailException | RecoveryEmailValidationException | Error $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => $e->getMessage(), 'success' => false]); $response->setStatus(500); @@ -177,10 +177,6 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setStatus(200); $response->setData(['success' => true]); - } catch (RecoveryEmailValidationException | Error $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); - $response->setData(['message' => $e->getMessage(), 'success' => false]); - $response->setStatus(500); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'An error occurred while creating your account!', 'success' => false]); -- GitLab