From 6deac219609a80054531730cdba1472b33c715da Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 28 Jul 2021 21:28:23 +0000 Subject: [PATCH] [EXCEPTION] Add Email related exceptions --- src/Util/Exception/EmailException.php | 47 ++++++++++++++++ src/Util/Exception/EmailTakenException.php | 53 +++++++++++++++++++ src/Util/Exception/NicknameTakenException.php | 2 +- 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/Util/Exception/EmailException.php create mode 100644 src/Util/Exception/EmailTakenException.php diff --git a/src/Util/Exception/EmailException.php b/src/Util/Exception/EmailException.php new file mode 100644 index 0000000000..9a2f0f9929 --- /dev/null +++ b/src/Util/Exception/EmailException.php @@ -0,0 +1,47 @@ +. +// }}} + +/** + * Email base exception + * + * @category Exception + * @package GNUsocial + * + * @author Hugo Sales + * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Util\Exception; + +class EmailException extends ClientException +{ + public function __construct(string $msg = null, int $code = 400) + { + if ($msg === null) { + $msg = $this->defaultMessage(); + } + parent::__construct($msg, $code); + } + + protected function defaultMessage(): string + { + return ''; + } +} diff --git a/src/Util/Exception/EmailTakenException.php b/src/Util/Exception/EmailTakenException.php new file mode 100644 index 0000000000..0be462a384 --- /dev/null +++ b/src/Util/Exception/EmailTakenException.php @@ -0,0 +1,53 @@ +. + +// }}} + +/** + * Email taken exception + * + * @category Exception + * @package GNUsocial + * + * @author Hugo Sales + * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Util\Exception; + +use function App\Core\I18n\_m; +use App\Entity\GSActor; + +class EmailTakenException extends EmailException +{ + public ?GSActor $profile = null; // the GSActor which occupies the email + + public function __construct(?GSActor $profile = null, ?string $msg = null, int $code = 400) + { + $this->profile = $profile; + parent::__construct($msg, $code); + } + + protected function defaultMessage(): string + { + // TRANS: Validation error in form for registration, profile and group settings, etc. + return _m('Email is already in use on this server.'); + } +} diff --git a/src/Util/Exception/NicknameTakenException.php b/src/Util/Exception/NicknameTakenException.php index 8cb33cb136..bb47a46179 100644 --- a/src/Util/Exception/NicknameTakenException.php +++ b/src/Util/Exception/NicknameTakenException.php @@ -20,7 +20,7 @@ // }}} /** - * Nickname empty exception + * Nickname taken exception * * @category Exception * @package GNUsocial