[11/06/2024] Les premières modifs + installation de quelques modules indispensables

This commit is contained in:
2024-06-11 14:57:59 +02:00
parent 5ac5653ae5
commit 77cf2c7cc6
1626 changed files with 171457 additions and 131 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace ReCaptcha\Action;
use ReCaptcha\Event\ReCaptchaCheckEvent;
use ReCaptcha\Event\ReCaptchaEvents;
use ReCaptcha\ReCaptcha;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class ReCaptchaAction implements EventSubscriberInterface
{
/** @var Request */
protected $request;
public function __construct(RequestStack $requestStack)
{
$this->request = $requestStack->getCurrentRequest();
}
public function checkCaptcha(ReCaptchaCheckEvent $event)
{
$requestUrl = "https://www.google.com/recaptcha/api/siteverify";
$secretKey = ReCaptcha::getConfigValue('secret_key');
$minScore = ReCaptcha::getConfigValue('min_score', 0.3);
$requestUrl .= "?secret=$secretKey";
$captchaResponse = $event->getCaptchaResponse();
if (null == $captchaResponse) {
$captchaResponse = $this->request->request->get('g-recaptcha-response');
}
$requestUrl .= "&response=$captchaResponse";
$remoteIp = $event->getRemoteIp();
if (null == $remoteIp) {
$remoteIp = $this->request->server->get('REMOTE_ADDR');
}
$requestUrl .= "&remoteip=$remoteIp";
$result = json_decode(file_get_contents($requestUrl), true);
if ($result['success'] == true && (!array_key_exists('score', $result) || $result['score'] > $minScore)) {
$event->setHuman(true);
}
}
public static function getSubscribedEvents()
{
return [
ReCaptchaEvents::CHECK_CAPTCHA_EVENT => ['checkCaptcha', 128],
];
}
}