Reorganize CAPTCHA handling classes #2112

This commit is contained in:
Kijin Sung 2023-06-19 22:27:25 +09:00
parent eb79a5c66f
commit ef77af5a39
6 changed files with 94 additions and 84 deletions

View file

@ -225,7 +225,7 @@ class spamfilterController extends spamfilter
function triggerCheckCaptcha(&$obj)
{
$config = ModuleModel::getModuleConfig('spamfilter');
if (!isset($config) || !isset($config->captcha) || !in_array($config->captcha->type, ['recaptcha','turnstile']) || !$config->captcha->site_key || !$config->captcha->secret_key)
if (!isset($config) || !isset($config->captcha) || !in_array($config->captcha->type, ['recaptcha', 'turnstile']) || !$config->captcha->site_key || !$config->captcha->secret_key)
{
return;
}
@ -260,16 +260,16 @@ class spamfilterController extends spamfilter
if (count($target_actions))
{
include_once __DIR__ . '/captcha/' . $config->captcha->type . '.php';
spamfilter_captcha::init($config->captcha);
$captcha_class = 'Rhymix\\Modules\\Spamfilter\\Captcha\\' . $config->captcha->type;
$captcha_class::init($config->captcha);
if (strncasecmp('proc', $obj->act, 4) === 0)
{
spamfilter_captcha::check();
$captcha_class::check();
}
else
{
$captcha = new spamfilter_captcha();
$captcha = new $captcha_class();
$captcha->setTargetActions($target_actions);
$captcha->addScripts();
Context::set('captcha', $captcha);