Files
newznab-tmux/app/Rules/RecaptchaRule.php
T
2026-03-26 10:48:12 +01:00

31 lines
695 B
PHP

<?php
declare(strict_types=1);
namespace App\Rules;
use App\Services\RecaptchaService;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class RecaptchaRule implements ValidationRule
{
/**
* Validate the reCAPTCHA response token.
*
* @param Closure(string): void $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! is_string($value) || $value === '') {
$fail('Please complete the captcha verification.');
return;
}
if (! RecaptchaService::verify($value)) {
$fail('The captcha verification failed. Please try again.');
}
}
}