mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-17 14:18:24 +01:00
Merge pull request #6428 from wordlesswind/ticket/16105
[ticket/16105] Use Google reCAPTCHA globally
This commit is contained in:
commit
21374390ad
@ -21,6 +21,20 @@
|
||||
<dd><input id="recaptcha_privkey" name="recaptcha_privkey" value="{RECAPTCHA_PRIVKEY}" size="50" type="text" /></dd>
|
||||
</dl>
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
<label>{{ lang('RECAPTCHA_V3_DOMAIN') ~ lang('COLON') }}</label>
|
||||
<br><span>{{ lang('RECAPTCHA_V3_DOMAIN_EXPLAIN') }}</span>
|
||||
</dt>
|
||||
<dd>
|
||||
{% for domain in RECAPTCHA_V2_DOMAINS %}
|
||||
<label>
|
||||
<input class="radio" name="recaptcha_v2_domain" type="radio" value="{{ domain }}"{{ domain == RECAPTCHA_V2_DOMAIN ? ' checked' }}>
|
||||
<span>{{ domain }}</span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
|
@ -15,18 +15,13 @@ namespace phpbb\captcha\plugins;
|
||||
|
||||
class recaptcha extends captcha_abstract
|
||||
{
|
||||
var $recaptcha_server = 'http://www.google.com/recaptcha/api';
|
||||
var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
|
||||
|
||||
var $response;
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
global $request;
|
||||
$this->recaptcha_server = $request->is_secure() ? $this->recaptcha_server_secure : $this->recaptcha_server;
|
||||
}
|
||||
|
||||
function init($type)
|
||||
@ -94,6 +89,12 @@ class recaptcha extends captcha_abstract
|
||||
}
|
||||
}
|
||||
|
||||
$recaptcha_domain = $request->variable('recaptcha_v2_domain', '', true);
|
||||
if (in_array($recaptcha_domain, recaptcha_v3::$supported_domains))
|
||||
{
|
||||
$config->set('recaptcha_v2_domain', $recaptcha_domain);
|
||||
}
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL');
|
||||
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
|
||||
}
|
||||
@ -110,9 +111,11 @@ class recaptcha extends captcha_abstract
|
||||
}
|
||||
|
||||
$template->assign_vars(array(
|
||||
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
|
||||
'CAPTCHA_NAME' => $this->get_service_name(),
|
||||
'U_ACTION' => $module->u_action,
|
||||
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
|
||||
'CAPTCHA_NAME' => $this->get_service_name(),
|
||||
'RECAPTCHA_V2_DOMAIN' => $config['recaptcha_v2_domain'] ?? recaptcha_v3::GOOGLE,
|
||||
'RECAPTCHA_V2_DOMAINS' => recaptcha_v3::$supported_domains,
|
||||
'U_ACTION' => $module->u_action,
|
||||
));
|
||||
|
||||
}
|
||||
@ -140,9 +143,10 @@ class recaptcha extends captcha_abstract
|
||||
{
|
||||
$contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx);
|
||||
$explain = $user->lang(($this->type != CONFIRM_POST) ? 'CONFIRM_EXPLAIN' : 'POST_CONFIRM_EXPLAIN', '<a href="' . $contact_link . '">', '</a>');
|
||||
$domain = $config['recaptcha_v2_domain'] ?? recaptcha_v3::GOOGLE;
|
||||
|
||||
$template->assign_vars(array(
|
||||
'RECAPTCHA_SERVER' => $this->recaptcha_server,
|
||||
'RECAPTCHA_SERVER' => sprintf('//%1$s/recaptcha/api', $domain),
|
||||
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
|
||||
'S_RECAPTCHA_AVAILABLE' => self::is_available(),
|
||||
'S_CONFIRM_CODE' => true,
|
||||
|
@ -30,6 +30,14 @@ class recaptcha_v3 extends captcha_abstract
|
||||
*/
|
||||
const GOOGLE = 'google.com';
|
||||
const RECAPTCHA = 'recaptcha.net';
|
||||
const RECAPTCHA_CN = 'recaptcha.google.cn';
|
||||
|
||||
/** @var string[] List of supported domains */
|
||||
static public $supported_domains = [
|
||||
self::GOOGLE,
|
||||
self::RECAPTCHA,
|
||||
self::RECAPTCHA_CN
|
||||
];
|
||||
|
||||
/** @var array CAPTCHA types mapped to their action */
|
||||
static protected $actions = [
|
||||
@ -180,9 +188,14 @@ class recaptcha_v3 extends captcha_abstract
|
||||
trigger_error($language->lang('EMPTY_RECAPTCHA_V3_REQUEST_METHOD') . adm_back_link($module->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$recaptcha_domain = $request->variable('recaptcha_v3_domain', '', true);
|
||||
if (in_array($recaptcha_domain, self::$supported_domains))
|
||||
{
|
||||
$config->set('recaptcha_v3_domain', $recaptcha_domain);
|
||||
}
|
||||
|
||||
$config->set('recaptcha_v3_key', $request->variable('recaptcha_v3_key', '', true));
|
||||
$config->set('recaptcha_v3_secret', $request->variable('recaptcha_v3_secret', '', true));
|
||||
$config->set('recaptcha_v3_domain', $request->variable('recaptcha_v3_domain', '', true));
|
||||
$config->set('recaptcha_v3_method', $recaptcha_v3_method);
|
||||
|
||||
foreach (self::$actions as $action)
|
||||
@ -211,7 +224,7 @@ class recaptcha_v3 extends captcha_abstract
|
||||
'RECAPTCHA_V3_SECRET' => $config['recaptcha_v3_secret'] ?? '',
|
||||
|
||||
'RECAPTCHA_V3_DOMAIN' => $config['recaptcha_v3_domain'] ?? self::GOOGLE,
|
||||
'RECAPTCHA_V3_DOMAINS' => [self::GOOGLE, self::RECAPTCHA],
|
||||
'RECAPTCHA_V3_DOMAINS' => self::$supported_domains,
|
||||
|
||||
'RECAPTCHA_V3_METHOD' => $config['recaptcha_v3_method'] ?? '',
|
||||
'RECAPTCHA_V3_METHODS' => [
|
||||
|
Loading…
x
Reference in New Issue
Block a user