pelican-panel-mirror/app/Rules/ValidTurnstileCaptcha.php
Boy132 45db06a1bd
Refactor captcha (#1068)
* refactor captcha

* add default error message

* prevent rule from being called multiple times

* fixes

* use config

* Update this to latest

* Remove this

---------

Co-authored-by: Lance Pioch <git@lance.sh>
2025-03-15 15:52:38 -04:00

20 lines
518 B
PHP

<?php
namespace App\Rules;
use App\Extensions\Captcha\Providers\CaptchaProvider;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class ValidTurnstileCaptcha implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$response = CaptchaProvider::get('turnstile')->validateResponse($value);
if (!$response['success']) {
$fail($response['message'] ?? 'Unknown error occurred, please try again');
}
}
}