Add tests for featured thumbnail generation; apply Pint formatting and related edits
This commit is contained in:
@@ -7,6 +7,10 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TurnstileCaptchaProvider implements CaptchaProviderInterface
|
||||
{
|
||||
private const DEFAULT_VERIFY_URL = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
||||
|
||||
private const DEFAULT_SCRIPT_URL = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'turnstile';
|
||||
@@ -14,7 +18,7 @@ class TurnstileCaptchaProvider implements CaptchaProviderInterface
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return (bool) config('registration.enable_turnstile', true)
|
||||
return (bool) config('services.turnstile.enabled', false)
|
||||
&& $this->siteKey() !== ''
|
||||
&& (string) config('services.turnstile.secret_key', '') !== '';
|
||||
}
|
||||
@@ -31,7 +35,7 @@ class TurnstileCaptchaProvider implements CaptchaProviderInterface
|
||||
|
||||
public function scriptUrl(): string
|
||||
{
|
||||
return (string) config('services.turnstile.script_url', 'https://challenges.cloudflare.com/turnstile/v0/api.js');
|
||||
return (string) config('services.turnstile.script_url', self::DEFAULT_SCRIPT_URL);
|
||||
}
|
||||
|
||||
public function verify(string $token, ?string $ip = null): bool
|
||||
@@ -47,23 +51,39 @@ class TurnstileCaptchaProvider implements CaptchaProviderInterface
|
||||
try {
|
||||
$response = Http::asForm()
|
||||
->timeout((int) config('services.turnstile.timeout', 5))
|
||||
->post((string) config('services.turnstile.verify_url', 'https://challenges.cloudflare.com/turnstile/v0/siteverify'), [
|
||||
->post((string) config('services.turnstile.verify_url', self::DEFAULT_VERIFY_URL), [
|
||||
'secret' => (string) config('services.turnstile.secret_key', ''),
|
||||
'response' => $token,
|
||||
'remoteip' => $ip,
|
||||
]);
|
||||
|
||||
if ($response->failed()) {
|
||||
Log::info('turnstile verification rejected registration attempt', [
|
||||
'ip' => $ip,
|
||||
'hostname' => data_get($response->json(), 'hostname'),
|
||||
'error_codes' => data_get($response->json(), 'error-codes', []),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) data_get($response->json(), 'success', false);
|
||||
$success = (bool) data_get($response->json(), 'success', false);
|
||||
|
||||
if (! $success) {
|
||||
Log::info('turnstile verification rejected registration attempt', [
|
||||
'ip' => $ip,
|
||||
'hostname' => data_get($response->json(), 'hostname'),
|
||||
'error_codes' => data_get($response->json(), 'error-codes', []),
|
||||
]);
|
||||
}
|
||||
|
||||
return $success;
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('turnstile verification request failed', [
|
||||
'message' => $exception->getMessage(),
|
||||
'ip' => $ip,
|
||||
]);
|
||||
|
||||
return false;
|
||||
return (bool) config('services.turnstile.fail_open', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,32 @@
|
||||
|
||||
namespace App\Services\Security;
|
||||
|
||||
use App\Services\Security\Captcha\TurnstileCaptchaProvider;
|
||||
|
||||
class TurnstileVerifier
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CaptchaVerifier $captchaVerifier,
|
||||
private readonly TurnstileCaptchaProvider $turnstileProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->captchaVerifier->provider() === 'turnstile'
|
||||
&& $this->captchaVerifier->isEnabled();
|
||||
return $this->turnstileProvider->isEnabled();
|
||||
}
|
||||
|
||||
public function siteKey(): string
|
||||
{
|
||||
return $this->turnstileProvider->siteKey();
|
||||
}
|
||||
|
||||
public function scriptUrl(): string
|
||||
{
|
||||
return $this->turnstileProvider->scriptUrl();
|
||||
}
|
||||
|
||||
public function verify(string $token, ?string $ip = null): bool
|
||||
{
|
||||
return $this->captchaVerifier->verify($token, $ip);
|
||||
return $this->turnstileProvider->verify($token, $ip);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user