Migrate Turnstile to package and cleanup

This commit is contained in:
dyzcdn
2025-12-23 09:02:10 +07:00
parent 12ae6fe45d
commit 91bb01bfd8
6 changed files with 141 additions and 44 deletions

View File

@@ -24,7 +24,7 @@ class ForgotPasswordController extends Controller
{ {
$request->validate([ $request->validate([
'email' => 'required|email', 'email' => 'required|email',
'cf-turnstile-response' => ['required', new \App\Rules\Turnstile], 'cf-turnstile-response' => ['required', new \RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile],
]); ]);
// We will send the password reset link to this user. Once we have attempted // We will send the password reset link to this user. Once we have attempted

View File

@@ -29,7 +29,7 @@ class AuthController extends Controller
$credentials = $request->validate([ $credentials = $request->validate([
'email' => ['required', 'email'], 'email' => ['required', 'email'],
'password' => ['required'], 'password' => ['required'],
'cf-turnstile-response' => ['required', new \App\Rules\Turnstile], 'cf-turnstile-response' => ['required', new \RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile],
]); ]);
// Find user by email // Find user by email
@@ -73,7 +73,7 @@ class AuthController extends Controller
'email' => 'required|string|email|max:255|unique:users', 'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8', 'password' => 'required|string|min:8',
'terms' => 'required|accepted', 'terms' => 'required|accepted',
'cf-turnstile-response' => ['required', new \App\Rules\Turnstile], 'cf-turnstile-response' => ['required', new \RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile],
]); ]);
$roleInfo = \App\Models\Role::where('name', 'customer')->first(); $roleInfo = \App\Models\Role::where('name', 'customer')->first();

View File

@@ -1,28 +0,0 @@
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Http;
class Turnstile implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$response = Http::asForm()->post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [
'secret' => env('TURNSTILE_SECRET_KEY'),
'response' => $value,
'remoteip' => request()->ip(),
]);
if (! $response->json('success')) {
$fail('The :attribute verification failed. Please try again.');
}
}
}

View File

@@ -15,7 +15,8 @@
"laravel/reverb": "^1.0", "laravel/reverb": "^1.0",
"laravel/socialite": "^5.24", "laravel/socialite": "^5.24",
"laravel/tinker": "^2.10.1", "laravel/tinker": "^2.10.1",
"laravolt/avatar": "^6.3" "laravolt/avatar": "^6.3",
"ryangjchandler/laravel-cloudflare-turnstile": "^3.0"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",

137
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "065b9d83adf2a17b87ed567b244f3790", "content-hash": "992a7cc59443753104146438fbf53602",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@@ -4954,6 +4954,141 @@
], ],
"time": "2024-06-11T12:45:25+00:00" "time": "2024-06-11T12:45:25+00:00"
}, },
{
"name": "ryangjchandler/laravel-cloudflare-turnstile",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/ryangjchandler/laravel-cloudflare-turnstile.git",
"reference": "c5712e515aa355397159e0b59fe331469bee5a87"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ryangjchandler/laravel-cloudflare-turnstile/zipball/c5712e515aa355397159e0b59fe331469bee5a87",
"reference": "c5712e515aa355397159e0b59fe331469bee5a87",
"shasum": ""
},
"require": {
"illuminate/contracts": "^11.0|^12.0",
"php": "^8.2",
"spatie/laravel-package-tools": "^1.13.0"
},
"require-dev": {
"larastan/larastan": "^3.1",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^8.0",
"orchestra/testbench": "^9.0|^10.0",
"pestphp/pest": "^3.7",
"pestphp/pest-plugin-laravel": "^3.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
"phpstan/phpstan-phpunit": "^1.0|^2.0",
"phpunit/phpunit": "^10.0|^11.5.3",
"spatie/laravel-ray": "^1.26",
"spatie/pest-plugin-snapshots": "^2.0"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"LaravelCloudflareTurnstile": "RyanChandler\\LaravelCloudflareTurnstile\\Facades\\LaravelCloudflareTurnstile"
},
"providers": [
"RyanChandler\\LaravelCloudflareTurnstile\\LaravelCloudflareTurnstileServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"RyanChandler\\LaravelCloudflareTurnstile\\": "src",
"RyanChandler\\LaravelCloudflareTurnstile\\Database\\Factories\\": "database/factories"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ryan Chandler",
"email": "support@ryangjchandler.co.uk",
"role": "Developer"
}
],
"description": "A simple package to help integrate Cloudflare Turnstile.",
"homepage": "https://github.com/ryangjchandler/laravel-cloudflare-turnstile",
"keywords": [
"laravel",
"laravel-cloudflare-turnstile",
"ryangjchandler"
],
"support": {
"issues": "https://github.com/ryangjchandler/laravel-cloudflare-turnstile/issues",
"source": "https://github.com/ryangjchandler/laravel-cloudflare-turnstile/tree/v3.0.1"
},
"time": "2025-12-16T15:56:01+00:00"
},
{
"name": "spatie/laravel-package-tools",
"version": "1.92.7",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-package-tools.git",
"reference": "f09a799850b1ed765103a4f0b4355006360c49a5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/f09a799850b1ed765103a4f0b4355006360c49a5",
"reference": "f09a799850b1ed765103a4f0b4355006360c49a5",
"shasum": ""
},
"require": {
"illuminate/contracts": "^9.28|^10.0|^11.0|^12.0",
"php": "^8.0"
},
"require-dev": {
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.7|^8.0|^9.0|^10.0",
"pestphp/pest": "^1.23|^2.1|^3.1",
"phpunit/php-code-coverage": "^9.0|^10.0|^11.0",
"phpunit/phpunit": "^9.5.24|^10.5|^11.5",
"spatie/pest-plugin-test-time": "^1.1|^2.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\LaravelPackageTools\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Tools for creating Laravel packages",
"homepage": "https://github.com/spatie/laravel-package-tools",
"keywords": [
"laravel-package-tools",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-package-tools/issues",
"source": "https://github.com/spatie/laravel-package-tools/tree/1.92.7"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2025-07-17T15:46:43+00:00"
},
{ {
"name": "symfony/clock", "name": "symfony/clock",
"version": "v7.3.0", "version": "v7.3.0",

View File

@@ -1,11 +0,0 @@
@props(['theme' => 'auto', 'size' => 'normal', 'tabindex' => 0])
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<div class="cf-turnstile"
data-sitekey="{{ env('TURNSTILE_SITE_KEY') }}"
data-theme="{{ $theme }}"
data-size="{{ $size }}"
data-tabindex="{{ $tabindex }}"
{{ $attributes }}
></div>