From fb7d9d6570f0beeead653161c2cbebbbd2a09e1f Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 5 Nov 2018 15:42:12 +0100 Subject: [PATCH] Add config/captcha.php and use it in place of direct env file call --- Changelog | 1 + app/Http/Controllers/Auth/ForgotPasswordController.php | 2 +- app/Http/Controllers/Auth/LoginController.php | 2 +- app/Http/Controllers/Auth/RegisterController.php | 2 +- app/Http/Controllers/ContactUsController.php | 2 +- config/captcha.php | 10 ++++++++++ resources/views/themes/Gentele/contact.tpl | 2 +- resources/views/themes/Gentele/forgottenpassword.tpl | 2 +- resources/views/themes/Gentele/login.tpl | 2 +- resources/views/themes/Gentele/register.tpl | 2 +- 10 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 config/captcha.php diff --git a/Changelog b/Changelog index 957359142..8ff623e1e 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-11-05 DariusIII + * Chg: Add config/captcha.php and use it in place of direct env file call * Chg: Update monolog/monolog to version 1.24.0 * Chg: Update ProcessReleases class release tagging 2018-11-04 DariusIII diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 38e0bb594..a1ef852c8 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -48,7 +48,7 @@ class ForgotPasswordController extends Controller if (empty($email) && empty($rssToken)) { app('smarty.view')->assign('error', 'Missing parameter(email and/or apikey to send password reset'); } else { - if (env('NOCAPTCHA_ENABLED') === true && (! empty(env('NOCAPTCHA_SECRET')) && ! empty(env('NOCAPTCHA_SITEKEY')))) { + if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { $this->validate($request, [ 'g-recaptcha-response' => 'required|captcha', ]); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 52fb89b13..39366bbd7 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -66,7 +66,7 @@ class LoginController extends Controller } if ($user !== null && ((env('FIREWALL_ENABLED') === true && \Firewall::isBlacklisted($user->host) === false) || env('FIREWALL_ENABLED') === false)) { - if (env('NOCAPTCHA_ENABLED') === true && (! empty(env('NOCAPTCHA_SECRET')) && ! empty(env('NOCAPTCHA_SITEKEY')))) { + if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { $this->validate($request, [ 'g-recaptcha-response' => ['required', 'captcha'], ]); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 4868a53e9..81cff7e5c 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -94,7 +94,7 @@ class RegisterController extends Controller 'password' => ['required', 'string', 'min:8', 'confirmed', 'regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/'], ]); - if (env('NOCAPTCHA_ENABLED') === true && (! empty(env('NOCAPTCHA_SECRET')) && ! empty(env('NOCAPTCHA_SITEKEY')))) { + if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { $this->validate($request, [ 'g-recaptcha-response' => ['required', 'captcha'], ]); diff --git a/app/Http/Controllers/ContactUsController.php b/app/Http/Controllers/ContactUsController.php index d54bbbd70..d37fecd95 100644 --- a/app/Http/Controllers/ContactUsController.php +++ b/app/Http/Controllers/ContactUsController.php @@ -22,7 +22,7 @@ class ContactUsController extends BasePageController 'username' => 'required', ]); - if (env('NOCAPTCHA_ENABLED') === true && (! empty(env('NOCAPTCHA_SECRET')) && ! empty(env('NOCAPTCHA_SITEKEY')))) { + if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { $this->validate($request, [ 'g-recaptcha-response' => 'required|captcha', ]); diff --git a/config/captcha.php b/config/captcha.php new file mode 100644 index 000000000..b8cdc943a --- /dev/null +++ b/config/captcha.php @@ -0,0 +1,10 @@ + env('NOCAPTCHA_SECRET', ''), + 'sitekey' => env('NOCAPTCHA_SITEKEY', ''), + 'enabled' => env('NOCAPTCHA_ENABLED', false), + 'options' => [ + 'timeout' => 30, + ], +]; diff --git a/resources/views/themes/Gentele/contact.tpl b/resources/views/themes/Gentele/contact.tpl index 8e1828dcf..fcacb6416 100755 --- a/resources/views/themes/Gentele/contact.tpl +++ b/resources/views/themes/Gentele/contact.tpl @@ -53,7 +53,7 @@ - {if {env('NOCAPTCHA_ENABLED')} == 1 && !empty({env('NOCAPTCHA_SITEKEY')}) && !empty({env('NOCAPTCHA_SECRET')})} + {if {config('captcha.enabled')} == 1 && !empty({config('captcha.sitekey')}) && !empty({config('captcha.secret')})} {NoCaptcha::display()}{NoCaptcha::renderJs()} {/if}