• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

klinge / sl-webapp / 18972011891

31 Oct 2025 12:06PM UTC coverage: 74.73% (+11.1%) from 63.602%
18972011891

push

github

klinge
Fixed phpcs errors

1662 of 2224 relevant lines covered (74.73%)

3.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.59
/App/Controllers/Auth/AuthBaseController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Controllers\Auth;
6

7
use App\Controllers\BaseController;
8
use App\Services\UrlGeneratorService;
9
use andkab\Turnstile\Turnstile;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Monolog\Logger;
12
use League\Container\Container;
13

14
abstract class AuthBaseController extends BaseController
15
{
16
    protected string $turnstileSecret;
17
    protected string $remoteIp;
18
    protected Turnstile $turnstile;
19
    protected Logger $logger;
20

21
    //Messages
22
    protected const RECAPTCHA_ERROR_MESSAGE = 'Kunde inte validera recaptcha. Försök igen.';
23

24
    public function __construct(
25
        UrlGeneratorService $urlGenerator,
26
        ServerRequestInterface $request,
27
        Logger $logger,
28
        Container $container,
29
        string $turnstileSecret
30
    ) {
31
        parent::__construct($urlGenerator, $request, $logger, $container);
17✔
32
        $this->logger = $logger;
17✔
33
        $this->turnstileSecret = $turnstileSecret;
17✔
34
        $this->remoteIp = $this->request->getServerParams()['REMOTE_ADDR'] ?? '127.0.0.1';
17✔
35
        $this->turnstile = new Turnstile($this->turnstileSecret);
17✔
36
    }
37

38
    /**
39
     * Validates the reCAPTCHA response.
40
     *
41
     * Verifies the Cloudflare Turnstile reCAPTCHA response against the expected hostname
42
     * and score threshold. Logs the verification result.
43
     *
44
     * @return bool True if reCAPTCHA verification succeeds, false otherwise
45
     */
46
    protected function validateRecaptcha(): bool
47
    {
48
        $token = $this->request->getParsedBody()['cf-turnstile-response'] ?? null;
2✔
49

50
        if (!$token) {
2✔
51
            $this->logger->warning('Turnstile token is missing from request');
×
52
            return false;
×
53
        }
54

55
        try {
56
            $verifyResponse = $this->turnstile->verify($token, $this->remoteIp);
2✔
57
            $success = $verifyResponse->isSuccess();
2✔
58

59
            if (!$success) {
2✔
60
                $this->logger->warning('Turnstile verification failed for IP: ' . $this->remoteIp);
1✔
61
            }
62

63
            return $success;
2✔
64
        } catch (\Exception $e) {
×
65
            $this->logger->error('Turnstile verification exception: ' . $e->getMessage());
×
66
            return false;
×
67
        }
68
    }
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc