From 7dc87cb54c0752824376cda6b0d2e187a7193c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 31 Oct 2022 18:15:33 +0100 Subject: [PATCH] Validate users' emails --- src/UserEmail.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/UserEmail.php b/src/UserEmail.php index 0d8dca94607..5a5510c016a 100644 --- a/src/UserEmail.php +++ b/src/UserEmail.php @@ -244,9 +244,7 @@ public static function showAddEmailButton(User $user) public function prepareInputForAdd($input) { - - // Check email validity - if (!isset($input['email']) || empty($input['email'])) { + if (!$this->checkInputEmailValidity($input)) { return false; } @@ -258,6 +256,27 @@ public function prepareInputForAdd($input) return parent::prepareInputForAdd($input); } + public function prepareInputForUpdate($input) + { + if (!$this->checkInputEmailValidity($input)) { + return false; + } + + return parent::prepareInputForUpdate($input); + } + + /** + * Check validity of email passed in input. + * + * @param array $input + * + * @return bool + */ + private function checkInputEmailValidity(array $input): bool + { + return isset($input['email']) && !empty($input['email']) && GLPIMailer::validateAddress($input['email']); + } + /** * @since 0.84