CaptchaValidator.php
1 month ago
RecaptchaValidator.php
2 months ago
TurnstileValidator.php
2 months ago
ValidationError.php
2 months ago
index.php
1 year ago
TurnstileValidator.php
36 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Captcha\Validator; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Captcha\TurnstileValidator as Validator; |
| 9 | |
| 10 | class TurnstileValidator { |
| 11 | |
| 12 | /** @var Validator */ |
| 13 | private $validator; |
| 14 | |
| 15 | public function __construct( |
| 16 | Validator $validator |
| 17 | ) { |
| 18 | $this->validator = $validator; |
| 19 | } |
| 20 | |
| 21 | public function validate(array $data): bool { |
| 22 | $token = $data['turnstileResponseToken'] ?? ''; |
| 23 | if (!is_string($token)) { |
| 24 | throw new ValidationError(__('CAPTCHA verification failed.', 'mailpoet')); |
| 25 | } |
| 26 | |
| 27 | try { |
| 28 | $this->validator->validate($token); |
| 29 | } catch (\Throwable $e) { |
| 30 | throw new ValidationError($e->getMessage(), [], 0, $e); |
| 31 | } |
| 32 | |
| 33 | return true; |
| 34 | } |
| 35 | } |
| 36 |