| Conditions | 4 |
| Paths | 6 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public static function verify(string $token, ?string $remoteIp = null): bool |
||
| 13 | { |
||
| 14 | $secret = config('captcha.turnstile.secret'); |
||
| 15 | |||
| 16 | if (empty($secret)) { |
||
| 17 | return false; |
||
| 18 | } |
||
| 19 | |||
| 20 | try { |
||
| 21 | $response = Http::asForm()->post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [ |
||
| 22 | 'secret' => $secret, |
||
| 23 | 'response' => $token, |
||
| 24 | 'remoteip' => $remoteIp ?? request()->ip(), |
||
| 25 | ]); |
||
| 26 | |||
| 27 | $result = $response->json(); |
||
| 28 | |||
| 29 | return isset($result['success']) && $result['success'] === true; |
||
| 30 | } catch (\Exception $e) { |
||
| 31 | \Log::error('Turnstile verification failed: '.$e->getMessage()); |
||
| 32 | |||
| 33 | return false; |
||
| 34 | } |
||
| 73 |