Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Validate users' emails
  • Loading branch information
cedric-anne authored and trasher committed Nov 3, 2022
1 parent 071c4ea commit 7dc87cb
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/UserEmail.php
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 7dc87cb

Please sign in to comment.