From 8bc4c0d8d0fb16d701d427e47939051d2d30d91a Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Fri, 26 Jul 2024 22:13:14 +0500 Subject: [PATCH] Made it possible to disable captcha. --- app/application/.env.example | 1 + .../app/Http/Controllers/AuthController.php | 4 +++- .../app/Http/Requests/AuthorizationRequest.php | 9 +++++++-- .../Http/Requests/Site/Feedback/SendRequest.php | 9 +++++++-- app/application/config/app.php | 9 +++++++++ app/application/resources/views/login.blade.php | 8 +++++--- .../resources/views/site/feedback/index.blade.php | 14 ++++++++------ 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app/application/.env.example b/app/application/.env.example index 61089d6..d32953a 100644 --- a/app/application/.env.example +++ b/app/application/.env.example @@ -5,6 +5,7 @@ APP_DEBUG=true APP_TIMEZONE=UTC APP_URL=http://localhost +APP_CAPTCHA=false CAPTCHA_API_DOMAIN=http://your-domain-captcha-or-IP:8081 CAPTCHA_PRIVATE_TOKEN= CAPTCHA_STATIC_PATH=http://your-domain-captcha-or-IP:8081/captcha diff --git a/app/application/app/Http/Controllers/AuthController.php b/app/application/app/Http/Controllers/AuthController.php index 6f13fea..d10b9d9 100644 --- a/app/application/app/Http/Controllers/AuthController.php +++ b/app/application/app/Http/Controllers/AuthController.php @@ -19,7 +19,9 @@ public function __construct( public function login(): View { - return view('login'); + return view('login', [ + 'captcha' => config('app.captcha', false), + ]); } public function authorization(AuthorizationRequest $request): RedirectResponse diff --git a/app/application/app/Http/Requests/AuthorizationRequest.php b/app/application/app/Http/Requests/AuthorizationRequest.php index 934d9c8..c9970fd 100644 --- a/app/application/app/Http/Requests/AuthorizationRequest.php +++ b/app/application/app/Http/Requests/AuthorizationRequest.php @@ -13,12 +13,17 @@ final class AuthorizationRequest extends FormRequest implements FormRequestDto */ public function rules(): array { - return [ + $rules = [ 'email' => ['required', 'email', 'max:255'], 'password' => ['required', 'min:3'], - 'captcha-verified' => ['captcha'], 'remember' => ['nullable', 'boolean'], ]; + + if (config('app.captcha', false)) { + $rules['captcha-verified'] = ['captcha']; + } + + return $rules; } public function getDto(): Authorization diff --git a/app/application/app/Http/Requests/Site/Feedback/SendRequest.php b/app/application/app/Http/Requests/Site/Feedback/SendRequest.php index befefb6..c873cee 100644 --- a/app/application/app/Http/Requests/Site/Feedback/SendRequest.php +++ b/app/application/app/Http/Requests/Site/Feedback/SendRequest.php @@ -32,12 +32,17 @@ public function attributes(): array */ public function rules(): array { - return [ + $rules = [ 'name' => ['nullable', 'string', 'max:255'], 'email' => ['nullable', 'string', 'max:255', 'email'], 'message' => ['required', 'string', 'max:5000'], - 'captcha-verified' => ['captcha'], ]; + + if (config('app.captcha', false)) { + $rules['captcha-verified'] = ['captcha']; + } + + return $rules; } public function getDto(): Send diff --git a/app/application/config/app.php b/app/application/config/app.php index 4f08f4e..683f309 100644 --- a/app/application/config/app.php +++ b/app/application/config/app.php @@ -28,6 +28,15 @@ 'env' => env('APP_ENV', 'production'), + /* + |-------------------------------------------------------------------------- + | Сaptcha + |-------------------------------------------------------------------------- + | + | Enables or disables captcha. + */ + 'captcha' => (bool) env('APP_CAPTCHA', false), + /* |-------------------------------------------------------------------------- | Application Debug Mode diff --git a/app/application/resources/views/login.blade.php b/app/application/resources/views/login.blade.php index 59e6483..f61034d 100644 --- a/app/application/resources/views/login.blade.php +++ b/app/application/resources/views/login.blade.php @@ -49,9 +49,11 @@ -
- @captcha -
+ @if($captcha) +
+ @captcha +
+ @endif
diff --git a/app/application/resources/views/site/feedback/index.blade.php b/app/application/resources/views/site/feedback/index.blade.php index fae1980..8bc14f0 100644 --- a/app/application/resources/views/site/feedback/index.blade.php +++ b/app/application/resources/views/site/feedback/index.blade.php @@ -8,12 +8,14 @@ -
- @captcha - @error('captcha-verified') - {{ $message }} - @enderror -
+ @if($captcha) +
+ @captcha + @error('captcha-verified') + {{ $message }} + @enderror +
+ @endif