mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-29 19:53:11 +01:00
43 lines
1.2 KiB
PHP
43 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();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|