Browse Source

Update captcha, use config_cache helper

Daniel Supernault 1 year ago
parent
commit
8a89e3c963

+ 1 - 1
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'

+ 3 - 3
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')
 			)

+ 1 - 1
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';
 		}
 

+ 1 - 1
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',

+ 1 - 1
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!';
         }

+ 8 - 0
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'
             ];
 

+ 1 - 1
resources/views/auth/email/forgot.blade.php

@@ -65,7 +65,7 @@
                                 </div>
                             </div>
 
-                            @if(config('captcha.enabled') || config('captcha.active.login') || config('captcha.active.register'))
+                            @if((bool) config_cache('captcha.enabled'))
                             <label class="font-weight-bold small text-muted">Captcha</label>
                             <div class="d-flex flex-grow-1">
                                 {!! Captcha::display(['data-theme' => 'dark']) !!}

+ 3 - 3
resources/views/auth/login.blade.php

@@ -76,10 +76,10 @@
                         </div>
 
                         @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')
                         	)

+ 1 - 1
resources/views/auth/passwords/email.blade.php

@@ -54,7 +54,7 @@
 	                            </div>
 	                        </div>
 
-							@if(config('captcha.enabled'))
+							@if((bool) config_cache('captcha.enabled'))
 							<label class="font-weight-bold small text-muted">Captcha</label>
 	                        <div class="d-flex flex-grow-1">
 	                            {!! Captcha::display(['data-theme' => 'dark']) !!}

+ 1 - 1
resources/views/auth/passwords/reset.blade.php

@@ -109,7 +109,7 @@
 	                            </div>
 	                        </div>
 
-							@if(config('captcha.enabled'))
+							@if((bool) config_cache('captcha.enabled'))
 							<label class="font-weight-bold small pt-3 text-muted">Captcha</label>
 	                        <div class="d-flex flex-grow-1">
 	                            {!! Captcha::display(['data-theme' => 'dark']) !!}

+ 1 - 1
resources/views/settings/parental-controls/invite-register-form.blade.php

@@ -91,7 +91,7 @@
                             </div>
                         </div>
 
-                        @if(config('captcha.enabled') || config('captcha.active.register'))
+                        @if((bool) config_cache('captcha.enabled'))
                         <div class="d-flex justify-content-center my-3">
                             {!! Captcha::display() !!}
                         </div>