From 65225b65a3f190e5cdc811362ac3cca363e62ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=20=E7=99=BD?= Date: Mon, 10 Jun 2024 20:49:23 +0800 Subject: [PATCH] v0.0.2 --- app/Http/Controllers/Auth/LoginController.php | 21 ++- .../Controllers/Auth/RegisterController.php | 14 +- composer.json | 1 + composer.lock | 136 +++++++++++++++++- config/turnstile.php | 36 +++++ resources/views/auth/login.blade.php | 114 ++++++++++++++- resources/views/auth/register.blade.php | 117 ++++++++++++++- 7 files changed, 429 insertions(+), 10 deletions(-) create mode 100644 config/turnstile.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index fc8a88c..4e80a95 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use Coderflex\LaravelTurnstile\Rules\TurnstileCheck; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller @@ -16,7 +17,7 @@ class LoginController extends Controller | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | - */ + */ use AuthenticatesUsers; @@ -37,4 +38,22 @@ public function __construct() $this->middleware('guest')->except('logout'); $this->middleware('auth')->only('logout'); } + + /** + * Validate the user login request. + * + * @param \Illuminate\Http\Request $request + * @return void + * + * @throws \Illuminate\Validation\ValidationException + */ + protected function validateLogin(Request $request) + { + $request->validate([ + $this->username() => 'required|string', + 'password' => 'required|string', + 'cf-turnstile-response' => ['required', new TurnstileCheck()], + ]); + } + } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 961ea36..240eb23 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\User; +use Coderflex\LaravelTurnstile\Rules\TurnstileCheck; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; @@ -19,7 +20,7 @@ class RegisterController extends Controller | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | - */ + */ use RegistersUsers; @@ -49,9 +50,10 @@ public function __construct() protected function validator(array $data) { return Validator::make($data, [ - 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], - 'password' => ['required', 'string', 'min:8', 'confirmed'], + 'name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'password' => ['required', 'string', 'min:8', 'confirmed'], + 'cf-turnstile-response' => ['required', new TurnstileCheck()], ]); } @@ -64,8 +66,8 @@ protected function validator(array $data) protected function create(array $data) { return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], + 'name' => $data['name'], + 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); } diff --git a/composer.json b/composer.json index 5b8720d..18ad01d 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^8.1", + "coderflex/laravel-turnstile": "^2.0", "guzzlehttp/guzzle": "^7.2", "jeroennoten/laravel-adminlte": "^3.11", "laravel/framework": "^10.10", diff --git a/composer.lock b/composer.lock index f34a318..5ede998 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a9e39c5d5e9d2a17dcb236298d3cca77", + "content-hash": "bb271a22f0d60e284a4d8bda9af25f99", "packages": [ { "name": "almasaeed2010/adminlte", @@ -104,6 +104,80 @@ ], "time": "2023-01-15T23:15:59+00:00" }, + { + "name": "coderflex/laravel-turnstile", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/coderflexx/laravel-turnstile.git", + "reference": "02d5604e32f9ea578b5a40bc92b97c8b726ca34b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/coderflexx/laravel-turnstile/zipball/02d5604e32f9ea578b5a40bc92b97c8b726ca34b", + "reference": "02d5604e32f9ea578b5a40bc92b97c8b726ca34b", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.7", + "illuminate/contracts": "^10.0|^11.0", + "php": "^8.1|^8.2", + "spatie/laravel-package-tools": "^1.14.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.0|^8.0", + "nunomaduro/larastan": "^2.0.1", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.0", + "pestphp/pest-plugin-arch": "^2.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Coderflex\\LaravelTurnstile\\LaravelTurnstileServiceProvider" + ], + "aliases": { + "LaravelTurnstile": "Coderflex\\LaravelTurnstile\\Facades\\LaravelTurnstile" + } + } + }, + "autoload": { + "psr-4": { + "Coderflex\\LaravelTurnstile\\": "src/", + "Coderflex\\LaravelTurnstile\\Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "ousid", + "email": "oussama@coderflex.com", + "role": "Developer" + } + ], + "description": "A package to help you implement the Cloudflare turnstile \"CAPTCHA Alternative\"", + "homepage": "https://github.com/coderflexx/laravel-turnstile", + "keywords": [ + "cloudflare", + "coderflex", + "laravel", + "laravel-turnstile", + "turnstile" + ], + "support": { + "issues": "https://github.com/coderflexx/laravel-turnstile/issues", + "source": "https://github.com/coderflexx/laravel-turnstile/tree/v2.0.1" + }, + "time": "2024-04-08T16:05:46+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -3461,6 +3535,66 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.4", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", + "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "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.16.4" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-03-20T07:29:11+00:00" + }, { "name": "symfony/console", "version": "v6.3.4", diff --git a/config/turnstile.php b/config/turnstile.php new file mode 100644 index 0000000..1a1c816 --- /dev/null +++ b/config/turnstile.php @@ -0,0 +1,36 @@ + env('TURNSTILE_SITE_KEY', null), + + 'turnstile_secret_key' => env('TURNSTILE_SECRET_KEY', null), + + /* + |-------------------------------------------------------------------------- + | Error Messages + |-------------------------------------------------------------------------- + | + | Here you can find the error messages for the application. You can modify + | or translate the error message as you like. + | + | Note that you can translate the error message directly, without wrapping + | them in translate helper. + | + */ + 'error_messages' => [ + 'turnstile_check_message' => 'The CAPTCHA thinks you are a robot! Please refresh and try again.', + ], +]; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 0c40972..803b6ae 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1 +1,113 @@ -@extends('adminlte::auth.login') \ No newline at end of file +@extends('adminlte::auth.auth-page', ['auth_type' => 'login']) + +@section('adminlte_css_pre') + +@stop + +@php( $login_url = View::getSection('login_url') ?? config('adminlte.login_url', 'login') ) +@php( $register_url = View::getSection('register_url') ?? config('adminlte.register_url', 'register') ) +@php( $password_reset_url = View::getSection('password_reset_url') ?? config('adminlte.password_reset_url', 'password/reset') ) + +@if (config('adminlte.use_route_url', false)) + @php( $login_url = $login_url ? route($login_url) : '' ) + @php( $register_url = $register_url ? route($register_url) : '' ) + @php( $password_reset_url = $password_reset_url ? route($password_reset_url) : '' ) +@else + @php( $login_url = $login_url ? url($login_url) : '' ) + @php( $register_url = $register_url ? url($register_url) : '' ) + @php( $password_reset_url = $password_reset_url ? url($password_reset_url) : '' ) +@endif + +@section('auth_header', __('adminlte::adminlte.login_message')) + +@section('auth_body') +
+ @csrf + + {{-- Email field --}} +
+ + +
+
+ +
+
+ + @error('email') + + {{ $message }} + + @enderror +
+ + {{-- Password field --}} +
+ + +
+
+ +
+
+ + @error('password') + + {{ $message }} + + @enderror +
+ +
+ + @error('cf-turnstile-response') + + {{ $message }} + + @enderror +
+ + {{-- Login field --}} +
+
+
+ + + +
+
+ +
+ +
+
+ +
+@stop + +@section('auth_footer') + {{-- Password reset link --}} + @if($password_reset_url) +

+ + {{ __('adminlte::adminlte.i_forgot_my_password') }} + +

+ @endif + + {{-- Register link --}} + @if($register_url) +

+ + {{ __('adminlte::adminlte.register_a_new_membership') }} + +

+ @endif +@stop diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 8522004..ddd0365 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1 +1,116 @@ -@extends('adminlte::auth.register') \ No newline at end of file +@extends('adminlte::auth.auth-page', ['auth_type' => 'register']) + +@php( $login_url = View::getSection('login_url') ?? config('adminlte.login_url', 'login') ) +@php( $register_url = View::getSection('register_url') ?? config('adminlte.register_url', 'register') ) + +@if (config('adminlte.use_route_url', false)) + @php( $login_url = $login_url ? route($login_url) : '' ) + @php( $register_url = $register_url ? route($register_url) : '' ) +@else + @php( $login_url = $login_url ? url($login_url) : '' ) + @php( $register_url = $register_url ? url($register_url) : '' ) +@endif + +@section('auth_header', __('adminlte::adminlte.register_message')) + +@section('auth_body') +
+ @csrf + + {{-- Name field --}} +
+ + +
+
+ +
+
+ + @error('name') + + {{ $message }} + + @enderror +
+ + {{-- Email field --}} +
+ + +
+
+ +
+
+ + @error('email') + + {{ $message }} + + @enderror +
+ + {{-- Password field --}} +
+ + +
+
+ +
+
+ + @error('password') + + {{ $message }} + + @enderror +
+ + {{-- Confirm password field --}} +
+ + +
+
+ +
+
+ + @error('password_confirmation') + + {{ $message }} + + @enderror +
+ +
+ + @error('cf-turnstile-response') + + {{ $message }} + + @enderror +
+ {{-- Register button --}} + + +
+@stop + +@section('auth_footer') +

+ + {{ __('adminlte::adminlte.i_already_have_a_membership') }} + +

+@stop