-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for Cloudflare Turnstile plugin.
- Loading branch information
Showing
9 changed files
with
95 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
"name": "Anselm Hannemann ", | ||
"email": "[email protected]" | ||
}], | ||
"autoload": { | ||
"psr-4": { | ||
|
@@ -24,6 +24,6 @@ | |
"optimize-autoloader": true | ||
}, | ||
"extra": { | ||
"installer-name": "uniform-hcaptcha" | ||
"installer-name": "uniform-turnstile" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'uniform-hcaptcha-empty' => '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.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'uniform-hcaptcha-empty' => '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.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Uniform\Guards; | ||
|
||
use Kirby\Http\Remote; | ||
use Uniform\Exceptions\Exception; | ||
|
||
class TurnstileGuard extends Guard | ||
{ | ||
/** | ||
* Turnstile HTML input field name | ||
* | ||
* @var string | ||
*/ | ||
const fieldName = 'turnstile-response'; | ||
|
||
/** | ||
* URL for the Turnstile verification | ||
* | ||
* @var string | ||
*/ | ||
const verificationUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* Verify the turnstile challenge | ||
* Remove the field from the form data if it was correct | ||
*/ | ||
public function perform() | ||
{ | ||
$turnstileChallenge = kirby()->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters