diff --git a/LICENSE b/LICENSE index 25406d4..3ba354a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Lukas Leitsch +Copyright (c) 2022 Anselm Hannemann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2ab2537..2dc69df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Uniform hCaptcha Guard +# Uniform Clouflare Turnstile Guard -A [Kirby 3](https://getkirby.com/) plugin implementing a [hCaptcha](https://www.hcaptcha.com/) guard for the [Uniform](https://github.com/mzur/kirby-uniform) plugin. +A [Kirby 3](https://getkirby.com/) plugin implementing a [Cloudflare Turnstile](https://developers.cloudflare.com/turnstile/) guard for the [Uniform](https://github.com/mzur/kirby-uniform) plugin. ## Installation @@ -9,7 +9,7 @@ A [Kirby 3](https://getkirby.com/) plugin implementing a [hCaptcha](https://www. Add the plugin to your project: ``` -composer require leitsch/kirby-uniform-hcaptcha +composer require anselmh/kirby-uniform-turnstile ``` ## Configuration @@ -18,8 +18,8 @@ Set the configuration in your `config.php` file: ```php return [ - 'leitsch.uniform-hcaptcha.siteKey' => 'my-site-key', - 'leitsch.uniform-hcaptcha.secretKey' => 'my-secret-key', + 'anselmh.uniform-turnstile.siteKey' => 'my-site-key', + 'anselmh.uniform-turnstile.secretKey' => 'my-secret-key', ]; ``` @@ -27,15 +27,15 @@ return [ ### Template -You can use the provided helper function to embed the hCaptcha into your template: +You can use the provided helper function to embed the Turnstile into your template: ```html+php - + ``` -In order for hCaptcha to work, you need to provide the hCaptcha JavaScript file. +In order for turnstile to work, you need to provide the Turnstile JavaScript file. -Use the helper function `hcaptchaScript()` in your template. +Use the helper function `turnstileScript()` in your template or add it to the template at right before the closing `` tag. **Example** @@ -47,22 +47,22 @@ Use the helper function `hcaptchaScript()` in your template. - + - + ``` ### Controller -In your controller you can use the [magic method](https://kirby-uniform.readthedocs.io/en/latest/guards/guards/#magic-methods) `hcaptchaGuard()` to enable the hCaptcha guard: +In your controller you can use the [magic method](https://kirby-uniform.readthedocs.io/en/latest/guards/guards/#magic-methods) `turnstileGuard()` to enable the turnstile guard: ```php $form = new Form(/* ... */); if ($kirby->request()->is('POST')) { - $form->hcaptchaGuard() + $form->turnstileGuard() ->emailAction(/* ... */); } ``` @@ -70,3 +70,4 @@ if ($kirby->request()->is('POST')) ## Credits - Thanks to Lukas Dürrenberger for the [Uniform reCAPTCHA Guard Plugin](https://github.com/eXpl0it3r/kirby-uniform-recaptcha) +- Thanks to Lukas Leitsch for the [Uniform hCaptcha Guard Plugin](https://github.com/lukasleitsch/kirby-uniform-hcaptcha) diff --git a/composer.json b/composer.json index 1c23b32..74b71e7 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,16 @@ { - "name": "leitsch/kirby-uniform-hcaptcha", - "description": "Kirby 3 hCaptcha guard for the Uniform plugin", + "name": "anselmh/kirby-uniform-turnstile", + "description": "Kirby 3 Cloudflare Turnstile guard for the Uniform plugin", "type": "kirby-plugin", "require": { "php": "^8.0", - "getkirby/composer-installer": "^1.1", + "getkirby/composer-installer": "^1.2", "mzur/kirby-uniform": "^5.0" }, "license": "MIT", "authors": [{ - "name": "Lukas Leitsch", - "email": "lukas@leitsch.org" + "name": "Anselm Hannemann ", + "email": "info@anselm-hannemann.com" }], "autoload": { "psr-4": { @@ -24,6 +24,6 @@ "optimize-autoloader": true }, "extra": { - "installer-name": "uniform-hcaptcha" + "installer-name": "uniform-turnstile" } } diff --git a/i18n/de.php b/i18n/de.php index 43ac3b9..d738857 100644 --- a/i18n/de.php +++ b/i18n/de.php @@ -1,6 +1,6 @@ 'Die hCaptcha Eingabe ist leer.', - 'uniform-hcaptcha-invalid' => 'Die hCaptcha Eingabe ist ungültig.' + 'uniform-turnstile-empty' => 'Die Cloudflare Turnstile Sicherheitsaufgabe wurde leider nicht aufgefüllt.', + 'uniform-turnstile-invalid' => 'Die Lösung für die Cloudflare Turnstile Sicherheitsaufgabe ist leider ungültig, probieren Sie es erneut.' ]; diff --git a/i18n/en.php b/i18n/en.php index 091598f..7c4473f 100644 --- a/i18n/en.php +++ b/i18n/en.php @@ -1,6 +1,6 @@ 'The hCaptcha value is empty.', - 'uniform-hcaptcha-invalid' => 'The hCaptcha value is invalid.' + 'uniform-turnstile-empty' => 'The Cloudflare Turnstile challenge was not solved.', + 'uniform-turnstile-invalid' => 'The Cloudflare Turnstile challenge response is invalid.' ]; diff --git a/index.php b/index.php index f682888..96fff6e 100644 --- a/index.php +++ b/index.php @@ -4,11 +4,10 @@ @include_once __DIR__.'/vendor/autoload.php'; -Kirby::plugin('leitsch/uniform-hcaptcha', [ +Kirby::plugin('anselmh/uniform-turnstile', [ 'options' => [ 'siteKey' => '', - 'secretKey' => '', - 'size' => 'normal', + 'secretKey' => '' ], 'translations' => [ 'en' => @include_once __DIR__.'/i18n/en.php', diff --git a/src/Guards/HcaptchaGuard.php b/src/Guards/HcaptchaGuard.php deleted file mode 100644 index b3ae9c3..0000000 --- a/src/Guards/HcaptchaGuard.php +++ /dev/null @@ -1,58 +0,0 @@ -request()->get(self::fieldName); - - if (empty($hcaptchaChallenge)) { - $this->reject(t('uniform-hcaptcha-empty'), self::fieldName); - } - - $secretKey = option('leitsch.uniform-hcaptcha.secretKey'); - - if (empty($secretKey)) { - throw new Exception('The hCaptcha secret key for Uniform is not configured'); - } - - $response = Remote::request(self::verificationUrl, [ - 'method' => 'POST', - 'data' => [ - 'secret' => $secretKey, - 'response' => $hcaptchaChallenge, - ], - ]); - - if ($response->code() !== 200 || $response->json()['success'] !== true) { - $this->reject(t('uniform-hcaptcha-invalid'), self::fieldName); - } - - $this->form->forget(self::fieldName); - } -} diff --git a/src/Guards/TurnstileGuard.php b/src/Guards/TurnstileGuard.php new file mode 100644 index 0000000..39fa180 --- /dev/null +++ b/src/Guards/TurnstileGuard.php @@ -0,0 +1,58 @@ +request()->get(self::fieldName); + + if (empty($turnstileChallenge)) { + $this->reject(t('uniform-turnstile-empty'), self::fieldName); + } + + $secretKey = option('anselmh.uniform-turnstile.secretKey'); + + if (empty($secretKey)) { + throw new Exception('The Turnstile secret key for Uniform is not configured'); + } + + $response = Remote::request(self::verificationUrl, [ + 'method' => 'POST', + 'data' => [ + 'secret' => $secretKey, + 'response' => $turnstileChallenge, + ], + ]); + + if ($response->code() !== 200 || $response->json()['success'] !== true) { + $this->reject(t('uniform-turnstile-invalid'), self::fieldName); + } + + $this->form->forget(self::fieldName); + } +} diff --git a/src/helpers.php b/src/helpers.php index 6b79a43..7f96d99 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,23 +2,24 @@ use Uniform\Exceptions\Exception as UniformException; -if (!function_exists('hcaptchaField')) { - function hcaptchaField(): string +if (!function_exists('turnstileField')) { + function turnstileField(): string { - $siteKey = option('leitsch.uniform-hcaptcha.siteKey'); - $size = option('leitsch.uniform-hcaptcha.size'); + $siteKey = option('anselmh.uniform-turnstile.siteKey'); if (empty($siteKey)) { - throw new UniformException('The hCaptcha sitekey for Uniform is not configured'); + throw new UniformException('The Turnstile sitekey for Uniform is not configured'); } - return '
'; + return '
'; } } -if (!function_exists('hcaptchaScript')) { - function hcaptchaScript(): string +if (!function_exists('turnstileScript')) { + function turnstileScript(): string { - return ''; + return ''; } } + +