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));
if(config('captcha.enabled')) {
if((bool) config_cache('captcha.enabled')) {
$rules = [
'email' => 'required|email',
'h-captcha-response' => 'required|captcha'

View File

@ -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')
)

View File

@ -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';
}

View File

@ -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',

View File

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

View File

@ -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'
];

View File

@ -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']) !!}

View File

@ -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')
)

View File

@ -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']) !!}

View File

@ -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']) !!}

View File

@ -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>