Skip to content

Commit

Permalink
Update captcha, use config_cache helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Mar 12, 2024
1 parent c96167f commit 8a89e3c
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function validateEmail(Request $request)

usleep(random_int(100000, 3000000));

if(config('captcha.enabled')) {
if((bool) config_cache('captcha.enabled')) {
$rules = [
'email' => 'required|email',
'h-captcha-response' => 'required|captcha'
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function validateLogin($request)
$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')
)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function ($attribute, $value, $fail) {
'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';
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function rules()
{
usleep(random_int(100000, 3000000));

if(config('captcha.enabled')) {
if((bool) config_cache('captcha.enabled')) {
return [
'token' => 'required',
'email' => 'required|email',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserEmailForgotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function store(Request $request)
'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!';
}
Expand Down
8 changes: 8 additions & 0 deletions app/Services/ConfigCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public static function get($key)
'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'
];

Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/email/forgot.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class="form-control form-control-lg bg-glass text-white"
</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']) !!}
Expand Down
6 changes: 3 additions & 3 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/passwords/email.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class="form-control form-control-lg bg-glass text-white"
</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']) !!}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/passwords/reset.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class="form-control form-control-lg bg-glass text-white{{ $errors->has('password
</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']) !!}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class="rounded-circle mr-2"
</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>
Expand Down

0 comments on commit 8a89e3c

Please sign in to comment.