Update captcha, use config_cache helper

This commit is contained in:
Daniel Supernault 2024-03-11 21:25:04 -06:00
parent c96167f2f7
commit 8a89e3c963
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
11 changed files with 22 additions and 14 deletions

View file

@ -62,7 +62,7 @@ class ForgotPasswordController extends Controller
usleep(random_int(100000, 3000000)); usleep(random_int(100000, 3000000));
if(config('captcha.enabled')) { if((bool) config_cache('captcha.enabled')) {
$rules = [ $rules = [
'email' => 'required|email', 'email' => 'required|email',
'h-captcha-response' => 'required|captcha' 'h-captcha-response' => 'required|captcha'

View file

@ -74,10 +74,10 @@ class LoginController extends Controller
$messages = []; $messages = [];
if( if(
config('captcha.enabled') || (bool) config_cache('captcha.enabled') &&
config('captcha.active.login') || (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()->has('login_attempts') &&
request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts') request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts')
) )

View file

@ -137,7 +137,7 @@ class RegisterController extends Controller
'password' => 'required|string|min:'.config('pixelfed.min_password_length').'|confirmed', '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'; $rules['h-captcha-response'] = 'required|captcha';
} }

View file

@ -50,7 +50,7 @@ class ResetPasswordController extends Controller
{ {
usleep(random_int(100000, 3000000)); usleep(random_int(100000, 3000000));
if(config('captcha.enabled')) { if((bool) config_cache('captcha.enabled')) {
return [ return [
'token' => 'required', 'token' => 'required',
'email' => 'required|email', 'email' => 'required|email',

View file

@ -34,7 +34,7 @@ class UserEmailForgotController extends Controller
'username.exists' => 'This username is no longer active or does not exist!' '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'; $rules['h-captcha-response'] = 'required|captcha';
$messages['h-captcha-response.required'] = 'You need to complete the captcha!'; $messages['h-captcha-response.required'] = 'You need to complete the captcha!';
} }

View file

@ -89,6 +89,14 @@ class ConfigCacheService
'pixelfed.app_registration_confirm_rate_limit_decay', 'pixelfed.app_registration_confirm_rate_limit_decay',
'instance.embed.profile', 'instance.embed.profile',
'instance.embed.post', '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' // 'system.user_mode'
]; ];

View file

@ -65,7 +65,7 @@
</div> </div>
</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> <label class="font-weight-bold small text-muted">Captcha</label>
<div class="d-flex flex-grow-1"> <div class="d-flex flex-grow-1">
{!! Captcha::display(['data-theme' => 'dark']) !!} {!! Captcha::display(['data-theme' => 'dark']) !!}

View file

@ -76,10 +76,10 @@
</div> </div>
@if( @if(
config('captcha.enabled') || (bool) config_cache('captcha.enabled') &&
config('captcha.active.login') || (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()->has('login_attempts') &&
request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts') request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts')
) )

View file

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

View file

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

View file

@ -91,7 +91,7 @@
</div> </div>
</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"> <div class="d-flex justify-content-center my-3">
{!! Captcha::display() !!} {!! Captcha::display() !!}
</div> </div>