Skip to content
Snippets Groups Projects
Commit 773ca7b2 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2:
Browse files

Issue #3441129 by Grevil: Error: Call to a member function getStatusCode() on...

Issue #3441129 by Grevil: Error: Call to a member function getStatusCode() on string in friendlycaptcha_captcha_validation() using local endpoint
parent 785edd72
No related branches found
No related tags found
1 merge request!24Issue #3441129 by Grevil: Error: Call to a member function getStatusCode() on string in friendlycaptcha_captcha_validation() using local endpoint
Pipeline #149099 passed with warnings
......@@ -5,6 +5,7 @@
* Friendly Captcha integration module.
*/
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Template\Attribute;
......@@ -140,7 +141,12 @@ function friendlycaptcha_captcha_validation($solution, $response, $element, $for
}
if ($config->get('api_endpoint') === 'local') {
$json = \Drupal::service('friendlycaptcha.siteverify')->verify($captchaSolution);
$result = \Drupal::service('friendlycaptcha.siteverify')->verify($captchaSolution);
$error = $result['error'] ?? 'None';
$loggerContent = new FormattableMarkup('Captcha validation failed: "@error".', [
'@error' => $error,
]);
$loggerContentString = $loggerContent->__toString();
}
else {
$options = [
......@@ -153,16 +159,20 @@ function friendlycaptcha_captcha_validation($solution, $response, $element, $for
// See http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html
'http_errors' => FALSE,
];
$response = \Drupal::httpClient()->post('https://api.friendlycaptcha.com/api/v1/siteverify', $options);
$responseContent = $response->getBody()->getContents();
$json = json_decode($responseContent, TRUE);
$apiResponse = \Drupal::httpClient()->post('https://api.friendlycaptcha.com/api/v1/siteverify', $options);
$apiResponseContent = $apiResponse->getBody()->getContents();
$result = json_decode($apiResponseContent, TRUE);
$loggerContent = new FormattableMarkup('Captcha validation failed: "@errors". Status code: "@status_code".', [
'@status_code' => $apiResponse->getStatusCode(),
'@errors' => isset($result['errors']) ? implode(', ', $result['errors']) : 'None',
]);
$loggerContentString = $loggerContent->__toString();
}
if (isset($json['success']) && $json['success'] == TRUE) {
if (isset($result['success']) && $result['success'] == TRUE) {
return TRUE;
}
\Drupal::logger('friendlycaptcha')->info('@status_code @data', ['@status_code' => $response->getStatusCode(), '@data' => (string) $responseContent]);
\Drupal::logger('friendlycaptcha')->info($loggerContentString);
return FALSE;
}
......@@ -2,7 +2,6 @@
namespace Drupal\friendlycaptcha\Form;
use Drupal\Component\Utility\Random;
use Drupal\Core\Asset\LibrariesDirectoryFileFinder;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -113,7 +112,7 @@ class FriendlyCaptchaAdminSettingsForm extends ConfigFormBase {
':input[name="friendlycaptcha_api_endpoint"]' => ['value' => 'local'],
],
],
];
];
if (!$this->libraryFileFinder->find('friendly-challenge')) {
$this->messenger()->addWarning(_friendlycaptcha_get_library_missing_message());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment