From 4e3ffa61153830380085d45966b08b1f95332f5c Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 19 Jun 2023 22:33:36 +0900 Subject: [PATCH] Use new HTTP class to communicate with reCAPTCHA/Turnstile servers #2112 --- modules/spamfilter/captcha/recaptcha.php | 18 ++++++++---------- modules/spamfilter/captcha/turnstile.php | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/modules/spamfilter/captcha/recaptcha.php b/modules/spamfilter/captcha/recaptcha.php index 1a6786a9f..99afbee64 100644 --- a/modules/spamfilter/captcha/recaptcha.php +++ b/modules/spamfilter/captcha/recaptcha.php @@ -4,6 +4,7 @@ namespace Rhymix\Modules\Spamfilter\Captcha; use Context; use Rhymix\Framework\Exception; +use Rhymix\Framework\HTTP; class reCAPTCHA { @@ -27,20 +28,17 @@ class reCAPTCHA throw new Exception('msg_recaptcha_invalid_response'); } - try - { - $verify_request = \Requests::post(self::$verify_url, array(), array( - 'secret' => self::$config->secret_key, - 'response' => $response, - 'remoteip' => \RX_CLIENT_IP, - )); - } - catch (\Requests_Exception $e) + $verify_request = HTTP::post(self::$verify_url, [ + 'secret' => self::$config->secret_key, + 'response' => $response, + 'remoteip' => \RX_CLIENT_IP, + ]); + if ($verify_request->getStatusCode() !== 200 || !$verify_request->getBody()) { throw new Exception('msg_recaptcha_connection_error'); } - $verify = @json_decode($verify_request->body, true); + $verify = @json_decode($verify_request->getBody(), true); if (!$verify || !$verify['success']) { throw new Exception('msg_recaptcha_server_error'); diff --git a/modules/spamfilter/captcha/turnstile.php b/modules/spamfilter/captcha/turnstile.php index c75970e91..6309041b4 100644 --- a/modules/spamfilter/captcha/turnstile.php +++ b/modules/spamfilter/captcha/turnstile.php @@ -4,6 +4,7 @@ namespace Rhymix\Modules\Spamfilter\Captcha; use Context; use Rhymix\Framework\Exception; +use Rhymix\Framework\HTTP; class Turnstile { @@ -27,20 +28,17 @@ class Turnstile throw new Exception('msg_recaptcha_invalid_response'); } - try - { - $verify_request = \Requests::post(self::$verify_url, array(), array( - 'secret' => self::$config->secret_key, - 'response' => $response, - 'remoteip' => \RX_CLIENT_IP, - )); - } - catch (\Requests_Exception $e) + $verify_request = HTTP::post(self::$verify_url, [ + 'secret' => self::$config->secret_key, + 'response' => $response, + 'remoteip' => \RX_CLIENT_IP, + ]); + if ($verify_request->getStatusCode() !== 200 || !$verify_request->getBody()) { throw new Exception('msg_recaptcha_connection_error'); } - $verify = @json_decode($verify_request->body, true); + $verify = @json_decode($verify_request->getBody(), true); if (!$verify || !$verify['success']) { throw new Exception('msg_recaptcha_server_error');