mirror of
https://github.com/brian8544/turtle-wow.git
synced 2025-01-01 04:14:35 +00:00
34 lines
967 B
PHP
34 lines
967 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Models\auth\EmailProviderBlacklist;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class CheckEmail implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$email = substr(strrchr($value, '@'), 1);
|
|
|
|
$emailProviderBlacklist = EmailProviderBlacklist::where('domain', $email)->first();
|
|
|
|
if ($emailProviderBlacklist) {
|
|
switch ($emailProviderBlacklist->banned) {
|
|
case 1:
|
|
$fail(__('custom.invalid_email', ['email' => $value]));
|
|
break;
|
|
case 2:
|
|
$fail(__('custom.unknown_provider', ['email' => $value, 'domain' => $email]));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|