2024-02-29 13:42:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use App\Facades\Settings;
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
|
|
|
|
class ComplyWithEmailRestrictionPolicy implements ValidationRule
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the validation rule.
|
|
|
|
*/
|
2024-03-29 09:42:54 +01:00
|
|
|
public function validate(string $attribute, mixed $value, Closure $fail) : void
|
2024-02-29 13:42:28 +01:00
|
|
|
{
|
|
|
|
$list = Settings::get('restrictList');
|
|
|
|
$regex = Settings::get('restrictRule');
|
2024-03-29 09:42:54 +01:00
|
|
|
|
2024-02-29 13:42:28 +01:00
|
|
|
$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();
|
|
|
|
}
|
2024-03-29 09:42:54 +01:00
|
|
|
} else {
|
2024-02-29 13:42:28 +01:00
|
|
|
if (! $validatesFilter || ! $validatesRegex) {
|
|
|
|
$fail('validation.custom.email.ComplyWithEmailRestrictionPolicy')->translate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|