mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Split CAPTCHA check and loading methods for easy integration into other parts of the site
This commit is contained in:
parent
c0f9c77902
commit
4c9b14f077
2 changed files with 54 additions and 17 deletions
|
|
@ -225,23 +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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($this->user->is_admin === 'Y')
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($config->captcha->target_users !== 'everyone' && $this->user->member_srl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($config->captcha->target_frequency !== 'every_time' && isset($_SESSION['recaptcha_authenticated']) && $_SESSION['recaptcha_authenticated'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!$config->captcha->target_devices[Mobile::isFromMobilePhone() ? 'mobile' : 'pc'])
|
||||
if (!SpamfilterModel::isCaptchaEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,6 +208,59 @@ class spamfilterModel extends spamfilter
|
|||
return new BaseObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if CAPTCHA is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCaptchaEnabled($target_action = null)
|
||||
{
|
||||
$config = ModuleModel::getModuleConfig('spamfilter');
|
||||
$user = Context::get('logged_info');
|
||||
if (!isset($config) || !isset($config->captcha) || !in_array($config->captcha->type, ['recaptcha', 'turnstile']) || !$config->captcha->site_key || !$config->captcha->secret_key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($user->is_admin === 'Y')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($config->captcha->target_users !== 'everyone' && $user->member_srl)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($config->captcha->target_frequency !== 'every_time' && isset($_SESSION['recaptcha_authenticated']) && $_SESSION['recaptcha_authenticated'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!$config->captcha->target_devices[Mobile::isFromMobilePhone() ? 'mobile' : 'pc'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($target_action && !$config->captcha->target_actions[$target_action])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a CAPTCHA instance.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function getCaptcha($target_action)
|
||||
{
|
||||
$config = ModuleModel::getModuleConfig('spamfilter');
|
||||
$captcha_class = 'Rhymix\\Modules\\Spamfilter\\Captcha\\' . $config->captcha->type;
|
||||
$captcha_class::init($config->captcha);
|
||||
|
||||
$captcha = new $captcha_class();
|
||||
$captcha->setTargetActions([$target_action => true]);
|
||||
$captcha->addScripts();
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the trackbacks have already been registered to a particular article
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue