30 lines
679 B
PHP
30 lines
679 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Settings;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class ValidRegistrationCode implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if (auth()->check()) {
|
|
return; // Skip validation for authenticated users
|
|
}
|
|
|
|
if ($value !== Settings::get('registrationCode')) {
|
|
$fail('Incorrect registration code provided');
|
|
}
|
|
}
|
|
}
|