From 8a89e3c9637147fe53b16098c2e6285f6a3f12e5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 11 Mar 2024 21:25:04 -0600 Subject: [PATCH] Update captcha, use config_cache helper --- app/Http/Controllers/Auth/ForgotPasswordController.php | 2 +- app/Http/Controllers/Auth/LoginController.php | 6 +++--- app/Http/Controllers/Auth/RegisterController.php | 2 +- app/Http/Controllers/Auth/ResetPasswordController.php | 2 +- app/Http/Controllers/UserEmailForgotController.php | 2 +- app/Services/ConfigCacheService.php | 8 ++++++++ resources/views/auth/email/forgot.blade.php | 2 +- resources/views/auth/login.blade.php | 6 +++--- resources/views/auth/passwords/email.blade.php | 2 +- resources/views/auth/passwords/reset.blade.php | 2 +- .../parental-controls/invite-register-form.blade.php | 2 +- 11 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 618c495e2..22562e985 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -62,7 +62,7 @@ class ForgotPasswordController extends Controller usleep(random_int(100000, 3000000)); - if(config('captcha.enabled')) { + if((bool) config_cache('captcha.enabled')) { $rules = [ 'email' => 'required|email', 'h-captcha-response' => 'required|captcha' diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 627a879cc..86ee52c84 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -74,10 +74,10 @@ class LoginController extends Controller $messages = []; if( - config('captcha.enabled') || - config('captcha.active.login') || + (bool) config_cache('captcha.enabled') && + (bool) config_cache('captcha.active.login') || ( - config('captcha.triggers.login.enabled') && + (bool) config_cache('captcha.triggers.login.enabled') && request()->session()->has('login_attempts') && request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts') ) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 8bdd57bf8..7568fca09 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -137,7 +137,7 @@ class RegisterController extends Controller 'password' => 'required|string|min:'.config('pixelfed.min_password_length').'|confirmed', ]; - if(config('captcha.enabled') || config('captcha.active.register')) { + if((bool) config_cache('captcha.enabled') && (bool) config_cache('captcha.active.register')) { $rules['h-captcha-response'] = 'required|captcha'; } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index a92c4e38d..166ec01e3 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -50,7 +50,7 @@ class ResetPasswordController extends Controller { usleep(random_int(100000, 3000000)); - if(config('captcha.enabled')) { + if((bool) config_cache('captcha.enabled')) { return [ 'token' => 'required', 'email' => 'required|email', diff --git a/app/Http/Controllers/UserEmailForgotController.php b/app/Http/Controllers/UserEmailForgotController.php index 33378c4d0..3889b9802 100644 --- a/app/Http/Controllers/UserEmailForgotController.php +++ b/app/Http/Controllers/UserEmailForgotController.php @@ -34,7 +34,7 @@ class UserEmailForgotController extends Controller 'username.exists' => 'This username is no longer active or does not exist!' ]; - if(config('captcha.enabled') || config('captcha.active.login') || config('captcha.active.register')) { + if((bool) config_cache('captcha.enabled')) { $rules['h-captcha-response'] = 'required|captcha'; $messages['h-captcha-response.required'] = 'You need to complete the captcha!'; } diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 7537830fc..8205dc3bd 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -89,6 +89,14 @@ class ConfigCacheService 'pixelfed.app_registration_confirm_rate_limit_decay', 'instance.embed.profile', 'instance.embed.post', + + 'captcha.enabled', + 'captcha.secret', + 'captcha.sitekey', + 'captcha.active.login', + 'captcha.active.register', + 'captcha.triggers.login.enabled', + 'captcha.triggers.login.attempts', // 'system.user_mode' ]; diff --git a/resources/views/auth/email/forgot.blade.php b/resources/views/auth/email/forgot.blade.php index 898d19fb5..e4b67d792 100644 --- a/resources/views/auth/email/forgot.blade.php +++ b/resources/views/auth/email/forgot.blade.php @@ -65,7 +65,7 @@ - @if(config('captcha.enabled') || config('captcha.active.login') || config('captcha.active.register')) + @if((bool) config_cache('captcha.enabled'))
{!! Captcha::display(['data-theme' => 'dark']) !!} diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 9df9ea8c9..0f77f778e 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -76,10 +76,10 @@
@if( - config('captcha.enabled') || - config('captcha.active.login') || + (bool) config_cache('captcha.enabled') && + (bool) config_cache('captcha.active.login') || ( - config('captcha.triggers.login.enabled') && + (bool) config_cache('captcha.triggers.login.enabled') && request()->session()->has('login_attempts') && request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts') ) diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 4f2825e29..19461fa29 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -54,7 +54,7 @@ - @if(config('captcha.enabled')) + @if((bool) config_cache('captcha.enabled'))
{!! Captcha::display(['data-theme' => 'dark']) !!} diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index 1a740fa7d..ecabcaddf 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -109,7 +109,7 @@
- @if(config('captcha.enabled')) + @if((bool) config_cache('captcha.enabled'))
{!! Captcha::display(['data-theme' => 'dark']) !!} diff --git a/resources/views/settings/parental-controls/invite-register-form.blade.php b/resources/views/settings/parental-controls/invite-register-form.blade.php index 5b894e8d2..a21808efa 100644 --- a/resources/views/settings/parental-controls/invite-register-form.blade.php +++ b/resources/views/settings/parental-controls/invite-register-form.blade.php @@ -91,7 +91,7 @@
- @if(config('captcha.enabled') || config('captcha.active.register')) + @if((bool) config_cache('captcha.enabled'))
{!! Captcha::display() !!}