mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Also separate target actions when auto-inserting CAPTCHA into forms #1815
This commit is contained in:
parent
2dc3e5e19b
commit
0970a7d7ad
3 changed files with 24 additions and 7 deletions
|
|
@ -264,6 +264,7 @@ class spamfilterController extends spamfilter
|
|||
{
|
||||
$captcha = new spamfilter_reCAPTCHA();
|
||||
$captcha->setTargetActions($target_actions);
|
||||
$captcha->addScripts();
|
||||
Context::set('captcha', $captcha);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,15 +48,15 @@ class spamfilter_reCAPTCHA
|
|||
$_SESSION['recaptcha_authenticated'] = true;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
public function addScripts()
|
||||
{
|
||||
if (!self::$scripts_added)
|
||||
{
|
||||
self::$scripts_added = true;
|
||||
Context::loadFile(array('./modules/spamfilter/tpl/js/recaptcha.js', 'body'));
|
||||
Context::addHtmlFooter('<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=reCaptchaCallback" async defer></script>');
|
||||
$html = '<div id="recaptcha-config" data-sitekey="%s" data-theme="%s" data-size="%s"></div>';
|
||||
$html = sprintf($html, escape(self::$config->site_key), self::$config->theme ?: 'light', self::$config->size ?: 'normal');
|
||||
$html = '<div id="recaptcha-config" data-sitekey="%s" data-theme="%s" data-size="%s" data-targets="%s"></div>';
|
||||
$html = sprintf($html, escape(self::$config->site_key), self::$config->theme ?: 'light', self::$config->size ?: 'normal', implode(',', array_keys($this->_target_actions)));
|
||||
Context::addHtmlFooter($html);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,31 @@ function reCaptchaCallback() {
|
|||
var recaptcha_config = $("#recaptcha-config");
|
||||
var recaptcha_instances = $(".g-recaptcha");
|
||||
var recaptcha_instance_id = 1;
|
||||
var recaptcha_targets = String(recaptcha_config.data("targets")).split(",");
|
||||
|
||||
if (recaptcha_instances.size() === 0) {
|
||||
if (recaptcha_instances.length === 0) {
|
||||
var autoinsert_candidates = $("form").filter(function() {
|
||||
var actinput = $("input[name='act']", this);
|
||||
if (actinput.size() && actinput.val() && actinput.val().match(/^proc.+(Insert(Document|Comment|)|Login|FindAccount|ResendAuthMail)/i)) {
|
||||
return true;
|
||||
if (actinput.length && actinput.val()) {
|
||||
var act = String(actinput.val());
|
||||
if (act.match(/^procMemberInsert$/i) && recaptcha_targets.indexOf("signup") > -1) {
|
||||
return true;
|
||||
}
|
||||
if (act.match(/^procMemberLogin$/i) && recaptcha_targets.indexOf("login") > -1) {
|
||||
return true;
|
||||
}
|
||||
if (act.match(/^procMember(FindAccount|ResendAuthMail)$/i) && recaptcha_targets.indexOf("recovery") > -1) {
|
||||
return true;
|
||||
}
|
||||
if (act.match(/^proc[A-Z][a-zA-Z0-9_]+InsertDocument$/i) && recaptcha_targets.indexOf("document") > -1) {
|
||||
return true;
|
||||
}
|
||||
if (act.match(/^proc[A-Z][a-zA-Z0-9_]+InsertComment$/i) && recaptcha_targets.indexOf("comment") > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
var procfilter = $(this).attr("onsubmit");
|
||||
if (procfilter && procfilter.match(/procFilter\b.+\binsert/i)) {
|
||||
if (procfilter && procfilter.match(/procFilter\b.+\binsert/i) && (recaptcha_targets.indexOf("document") > -1 || recaptcha_targets.indexOf("comment") > -1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue