web-base/Core/API/VerifyCaptcha.class.php

36 lines
1009 B
PHP
Raw Permalink Normal View History

2020-06-26 23:32:45 +02:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\API;
2020-06-26 23:32:45 +02:00
2022-11-18 18:06:46 +01:00
use Core\API\Parameter\StringType;
use Core\Objects\Context;
2020-06-26 23:32:45 +02:00
class VerifyCaptcha extends Request {
2022-06-20 19:52:31 +02:00
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, array(
2020-06-26 23:32:45 +02:00
"captcha" => new StringType("captcha"),
"action" => new StringType("action"),
));
$this->isPublic = false;
}
2022-02-21 13:01:03 +01:00
public function _execute(): bool {
2022-06-20 19:52:31 +02:00
$settings = $this->context->getSettings();
2024-04-23 14:05:29 +02:00
$captchaProvider = $settings->getCaptchaProvider();
if ($captchaProvider === null) {
return $this->createError("No Captcha configured.");
2022-06-17 20:53:35 +02:00
}
2020-06-26 23:32:45 +02:00
$captcha = $this->getParam("captcha");
$action = $this->getParam("action");
2024-04-23 14:05:29 +02:00
$this->success = $captchaProvider->verify($captcha, $action);
$this->lastError = $captchaProvider->getError();
2020-06-26 23:32:45 +02:00
return $this->success;
}
2024-04-23 12:14:28 +02:00
public static function getDescription(): string {
return "Verifies a captcha response. This API is for internal use only.";
}
2020-06-26 23:32:45 +02:00
}