Changeset View
Changeset View
Standalone View
Standalone View
src/app/Rules/UserEmailDomain.php
Show All 18 Lines | class UserEmailDomain implements Rule | ||||
public function __construct($domains = null) | public function __construct($domains = null) | ||||
{ | { | ||||
$this->domains = $domains; | $this->domains = $domains; | ||||
} | } | ||||
/** | /** | ||||
* Determine if the validation rule passes. | * Determine if the validation rule passes. | ||||
* | * | ||||
* Validation of local part of an email address that's | * Validation of a domain part of an email address that's | ||||
* going to be user's login. | * going to be user's login. | ||||
* | * | ||||
* @param string $attribute Attribute name | * @param string $attribute Attribute name | ||||
* @param mixed $domain Domain part of email address | * @param mixed $domain Domain part of email address | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function passes($attribute, $domain): bool | public function passes($attribute, $domain): bool | ||||
{ | { | ||||
// don't allow @localhost and other no-fqdn | // don't allow @localhost and other non-fqdn | ||||
if (empty($domain) || strpos($domain, '.') === false || stripos($domain, 'www.') === 0) { | if ( | ||||
empty($domain) | |||||
|| !is_string($domain) | |||||
|| strpos($domain, '.') === false | |||||
|| stripos($domain, 'www.') === 0 | |||||
) { | |||||
$this->message = \trans('validation.domaininvalid'); | |||||
return false; | |||||
} | |||||
// Check the max length, according to the database column length | |||||
if (strlen($domain) > 191) { | |||||
$this->message = \trans('validation.domaininvalid'); | $this->message = \trans('validation.domaininvalid'); | ||||
return false; | return false; | ||||
} | } | ||||
$domain = Str::lower($domain); | $domain = Str::lower($domain); | ||||
// Use email validator to validate the domain part | // Use email validator to validate the domain part | ||||
$v = Validator::make(['email' => 'user@' . $domain], ['email' => 'required|email']); | $v = Validator::make(['email' => 'user@' . $domain], ['email' => 'required|email']); | ||||
Show All 24 Lines |