mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-25 16:39:13 +01:00
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Facades\Settings;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class ComplyWithEmailRestrictionPolicy implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail) : void
|
|
{
|
|
$list = Settings::get('restrictList');
|
|
$regex = Settings::get('restrictRule');
|
|
|
|
$validatesFilter = true;
|
|
$validatesRegex = true;
|
|
|
|
if (Settings::get('restrictRegistration') == true) {
|
|
if ($list && ! in_array($value, explode('|', $list))) {
|
|
$validatesFilter = false;
|
|
}
|
|
if ($regex && ! preg_match('/' . $regex . '/', $value)) {
|
|
$validatesRegex = false;
|
|
}
|
|
|
|
if ($list && $regex) {
|
|
if (! $validatesFilter && ! $validatesRegex) {
|
|
$fail('validation.custom.email.ComplyWithEmailRestrictionPolicy')->translate();
|
|
}
|
|
} else {
|
|
if (! $validatesFilter || ! $validatesRegex) {
|
|
$fail('validation.custom.email.ComplyWithEmailRestrictionPolicy')->translate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|