2024-05-03 19:05:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Core\API\Traits;
|
|
|
|
|
|
|
|
use Core\API\Parameter\StringType;
|
|
|
|
use Core\API\VerifyCaptcha;
|
|
|
|
use Core\Objects\Context;
|
|
|
|
|
|
|
|
trait Captcha {
|
|
|
|
|
2024-05-04 17:06:39 +02:00
|
|
|
function addCaptchaParameters(Context $context, array &$parameters): void {
|
|
|
|
$settings = $context->getSettings();
|
2024-05-03 19:05:43 +02:00
|
|
|
if ($settings->isCaptchaEnabled()) {
|
|
|
|
$parameters["captcha"] = new StringType("captcha");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkCaptcha(string $action): bool {
|
|
|
|
$settings = $this->context->getSettings();
|
|
|
|
if ($settings->isCaptchaEnabled()) {
|
|
|
|
$captcha = $this->getParam("captcha");
|
|
|
|
$req = new VerifyCaptcha($this->context);
|
|
|
|
if (!$req->execute(array("captcha" => $captcha, "action" => $action))) {
|
|
|
|
return $this->createError($req->getLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|