Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e657e0f authored by Ronak Patel's avatar Ronak Patel
Browse files

Merge branch 'dev/validation-exception' into 'main'

Added Validation Exception to show validation message

See merge request !134
parents f5b5103f 3ad6fe70
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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;
@@ -168,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);
+9 −0
Original line number Diff line number Diff line
<?php

namespace OCA\EcloudAccounts\Exception;

class RecoveryEmailValidationException extends \Exception {
	public function __construct($message = null, $code = 0) {
		parent::__construct($message, $code);
	}
}
+4 −3
Original line number Diff line number Diff line
@@ -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 OCP\Defaults;
use OCP\IConfig;
use OCP\ILogger;
@@ -267,13 +268,13 @@ class UserService {
	 */
	public function validateRecoveryEmail(string $recoveryEmail): void {
		if (!$this->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->blackListService->isBlacklistedEmail($recoveryEmail)) {
			throw new BlacklistedEmailException('The domain of this email address is blacklisted. Please provide another recovery address.');