mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Add reCAPTCHA addon for signup page
This commit is contained in:
parent
e96ac0ba7a
commit
bfc212cc09
6 changed files with 108 additions and 2 deletions
47
addons/recaptcha/conf/info.xml
Normal file
47
addons/recaptcha/conf/info.xml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<addon version="0.2">
|
||||
<title xml:lang="ko">reCAPTCHA</title>
|
||||
<title xml:lang="en">reCAPTCHA</title>
|
||||
<description xml:lang="ko">구글 reCAPTCHA 서비스를 사용하여 자동 가입 스팸을 방지합니다.</description>
|
||||
<description xml:lang="en">Prevent automated signups and spam with Google's reCAPTCHA service.</description>
|
||||
<version>1.0.0</version>
|
||||
<date>2016-05-27</date>
|
||||
<author email_address="kijin@kijinsung.com" link="https://github.com/kijin">
|
||||
<name xml:lang="ko">Kijin Sung</name>
|
||||
<name xml:lang="en">Kijin Sung</name>
|
||||
</author>
|
||||
<extra_vars>
|
||||
<var name="site_key" type="text">
|
||||
<title xml:lang="ko">Site Key</title>
|
||||
<title xml:lang="en">Site Key</title>
|
||||
</var>
|
||||
<var name="secret_key" type="text">
|
||||
<title xml:lang="ko">Secret Key</title>
|
||||
<title xml:lang="en">Secret Key</title>
|
||||
</var>
|
||||
<var name="theme" type="select">
|
||||
<title xml:lang="ko">테마</title>
|
||||
<title xml:lang="en">Theme</title>
|
||||
<options value="light">
|
||||
<title xml:lang="ko">밝은 테마</title>
|
||||
<title xml:lang="en">Light</title>
|
||||
</options>
|
||||
<options value="dark">
|
||||
<title xml:lang="ko">어두운 테마</title>
|
||||
<title xml:lang="en">Dark</title>
|
||||
</options>
|
||||
</var>
|
||||
<var name="size" type="select">
|
||||
<title xml:lang="ko">크기</title>
|
||||
<title xml:lang="en">Size</title>
|
||||
<options value="normal">
|
||||
<title xml:lang="ko">보통</title>
|
||||
<title xml:lang="en">Normal</title>
|
||||
</options>
|
||||
<options value="compact">
|
||||
<title xml:lang="ko">작게</title>
|
||||
<title xml:lang="en">Compact</title>
|
||||
</options>
|
||||
</var>
|
||||
</extra_vars>
|
||||
</addon>
|
||||
3
addons/recaptcha/lang/en.php
Normal file
3
addons/recaptcha/lang/en.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
$lang->msg_recaptcha_server_error = 'An error occurred while verifying your reCAPTCHA response.';
|
||||
$lang->msg_recaptcha_invalid_response = 'Please check reCAPTCHA.';
|
||||
3
addons/recaptcha/lang/ko.php
Normal file
3
addons/recaptcha/lang/ko.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
$lang->msg_recaptcha_server_error = 'reCAPTCHA 스팸방지 서버와 통신하는 도중 오류가 발생했습니다.';
|
||||
$lang->msg_recaptcha_invalid_response = 'reCAPTCHA 스팸방지 기능을 체크해 주십시오.';
|
||||
53
addons/recaptcha/recaptcha.addon.php
Normal file
53
addons/recaptcha/recaptcha.addon.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
if (!defined('RX_BASEDIR') || !$addon_info->site_key || !$addon_info->secret_key || $called_position !== 'before_module_init')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (preg_match('/^dispMemberSignUp/i', Context::get('act')))
|
||||
{
|
||||
getController('module')->addTriggerFunction('moduleObject.proc', 'after', function() use($addon_info) {
|
||||
$html = '<div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-size="%s"></div>';
|
||||
$html = sprintf($html, escape($addon_info->site_key), $addon_info->theme ?: 'light', $addon_info->size ?: 'normal');
|
||||
Context::addHtmlHeader('<script src="https://www.google.com/recaptcha/api.js" async defer></script>');
|
||||
Context::getInstance()->formTags[] = (object)array(
|
||||
'name' => 'recaptcha',
|
||||
'title' => 'reCAPTCHA',
|
||||
'inputTag' => $html,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (preg_match('/^procMemberInsert/i', Context::get('act')))
|
||||
{
|
||||
getController('module')->addTriggerFunction('moduleObject.proc', 'before', function() use($addon_info) {
|
||||
$response = Context::get('g-recaptcha-response');
|
||||
if (!$response)
|
||||
{
|
||||
return new Object(-1, lang('recaptcha.msg_recaptcha_invalid_response'));
|
||||
}
|
||||
|
||||
$verify_url = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
$verify_request = \Requests::post($recaptcha_verify_url, array(), array(
|
||||
'secret' => $addon_info->secret_key,
|
||||
'response' => $recaptcha_response,
|
||||
'remoteip' => \RX_CLIENT_IP,
|
||||
));
|
||||
|
||||
$verify = @json_decode($verify_request->body, true);
|
||||
var_dump($verify);exit;
|
||||
if ($verify && isset($verify['error-codes']) && in_array('invalid-input-response', $verify['error-codes']))
|
||||
{
|
||||
return new Object(-1, lang('recaptcha.msg_recaptcha_invalid_response'));
|
||||
}
|
||||
elseif (!$verify || !$verify['success'] || (isset($verify['error-codes']) && $verify['error-codes']))
|
||||
{
|
||||
return new Object(-1, lang('recaptcha.msg_recaptcha_server_error'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1301,7 +1301,7 @@ class ModuleHandler extends Handler
|
|||
foreach($trigger_functions as $item)
|
||||
{
|
||||
$before_each_trigger_time = microtime(true);
|
||||
$item($obj);
|
||||
$output = $item($obj);
|
||||
$after_each_trigger_time = microtime(true);
|
||||
|
||||
if ($trigger_name !== 'common.writeSlowlog')
|
||||
|
|
|
|||
|
|
@ -110,4 +110,4 @@
|
|||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
<include target="./common_footer.html" />
|
||||
<include target="./common_footer.html" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue