mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17413] Add acp settings for turnstile captcha
PHPBB-17413
This commit is contained in:
parent
b55b42d09f
commit
2500f722ab
5 changed files with 148 additions and 5 deletions
50
phpBB/adm/style/captcha_turnstile_acp.html
Normal file
50
phpBB/adm/style/captcha_turnstile_acp.html
Normal file
|
@ -0,0 +1,50 @@
|
|||
{% include('overall_header.html') %}
|
||||
|
||||
<a id="maincontent"></a>
|
||||
|
||||
<h1>{{ lang('ACP_VC_SETTINGS') }}</h1>
|
||||
|
||||
<p>{{ lang('ACP_VC_SETTINGS_EXPLAIN') }}</p>
|
||||
|
||||
<form id="acp_captcha" method="post" action="{{ U_ACTION }}">
|
||||
<fieldset>
|
||||
<legend>{{ lang('GENERAL_OPTIONS') }}</legend>
|
||||
<dl>
|
||||
<dt>
|
||||
<label for="captcha_turnstile_sitekey">{{ lang('CAPTCHA_TURNSTILE_SITEKEY') ~ lang('COLON') }}</label><br>
|
||||
<span>{{ lang('CAPTCHA_TURNSTILE_SITEKEY_EXPLAIN') }}</span>
|
||||
</dt>
|
||||
<dd><input id="captcha_turnstile_sitekey" name="captcha_turnstile_sitekey" value="{{ CAPTCHA_TURNSTILE_SITEKEY }}" size="50" type="text" /></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>
|
||||
<label for="captcha_turnstile_secret">{{ lang('CAPTCHA_TURNSTILE_SECRET') ~ lang('COLON') }}</label><br>
|
||||
<span>{{ lang('CAPTCHA_TURNSTILE_SECRET_EXPLAIN') }}</span>
|
||||
</dt>
|
||||
<dd><input id="captcha_turnstile_secret" name="captcha_turnstile_secret" value="{{ CAPTCHA_TURNSTILE_SECRET }}" size="50" type="text" /></dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{{ lang('PREVIEW') }}</legend>
|
||||
{% if PREVIEW %}
|
||||
<div class="successbox">
|
||||
<h3>{{ lang('WARNING') }}</h3>
|
||||
<p>{{ lang('CAPTCHA_PREVIEW_MSG') }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include(CAPTCHA_PREVIEW) %}
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>{{ lang('ACP_SUBMIT_CHANGES') }}</legend>
|
||||
<p class="submit-buttons">
|
||||
<input class="button1" type="submit" id="submit" name="submit" value="{{ lang('SUBMIT') }}" />
|
||||
<input class="button2" type="reset" id="reset" name="reset" value="{{ lang('RESET') }}" />
|
||||
</p>
|
||||
<input type="hidden" name="select_captcha" value="{{ CAPTCHA_NAME }}" />
|
||||
<input type="hidden" name="configure" value="1" />
|
||||
{{ S_FORM_TOKEN }}
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{% include('overall_footer.html') %}
|
|
@ -61,6 +61,10 @@ services:
|
|||
arguments:
|
||||
- '@config'
|
||||
- '@language'
|
||||
- '@log'
|
||||
- '@request'
|
||||
- '@template'
|
||||
- '@user'
|
||||
calls:
|
||||
- ['set_name', ['core.captcha.plugins.turnstile']]
|
||||
tags:
|
||||
|
|
|
@ -37,5 +37,9 @@ if (empty($lang) || !is_array($lang))
|
|||
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
|
||||
|
||||
$lang = array_merge($lang, [
|
||||
'CAPTCHA_TURNSTILE' => 'Turnstile',
|
||||
'CAPTCHA_TURNSTILE' => 'Turnstile',
|
||||
'CAPTCHA_TURNSTILE_SITEKEY' => 'Sitekey',
|
||||
'CAPTCHA_TURNSTILE_SITEKEY_EXPLAIN' => 'Your Turnstile sitekey. The sitekey can be retrieved from your <a href="https://dash.cloudflare.com/?to=/:account/turnstile">Cloudflare dashboard</a>.',
|
||||
'CAPTCHA_TURNSTILE_SECRET' => 'Secret key',
|
||||
'CAPTCHA_TURNSTILE_SECRET_EXPLAIN' => 'Your Turnstile secret key. The secret key can be retrieved from your <a href="https://dash.cloudflare.com/?to=/:account/turnstile">Cloudflare dashboard</a>.',
|
||||
]);
|
||||
|
|
|
@ -116,5 +116,12 @@ interface plugin_interface
|
|||
*/
|
||||
public function garbage_collect(int $confirm_type = 0): void;
|
||||
|
||||
/**
|
||||
* Display acp page
|
||||
*
|
||||
* @param mixed $id ACP module id
|
||||
* @param mixed $module ACP module name
|
||||
* @return void
|
||||
*/
|
||||
public function acp_page($id, $module): void;
|
||||
}
|
||||
|
|
|
@ -15,23 +15,54 @@ namespace phpbb\captcha\plugins;
|
|||
|
||||
use phpbb\config\config;
|
||||
use phpbb\language\language;
|
||||
use phpbb\log\log_interface;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
use phpbb\user;
|
||||
|
||||
class turnstile implements plugin_interface
|
||||
{
|
||||
private const API_ENDPOINT = 'https://api.cloudflare.com/client/v4/captcha/validate';
|
||||
|
||||
/** @var config */
|
||||
protected $config;
|
||||
protected config $config;
|
||||
|
||||
/** @var language */
|
||||
protected $language;
|
||||
protected language $language;
|
||||
|
||||
/** @var log_interface */
|
||||
protected log_interface $log;
|
||||
|
||||
/** @var request_interface */
|
||||
protected request_interface $request;
|
||||
|
||||
/** @var template */
|
||||
protected template $template;
|
||||
|
||||
/** @var user */
|
||||
protected user $user;
|
||||
|
||||
/** @var string Service name */
|
||||
protected string $service_name = '';
|
||||
|
||||
public function __construct(config $config, language $language)
|
||||
/**
|
||||
* Constructor for turnstile captcha plugin
|
||||
*
|
||||
* @param config $config
|
||||
* @param language $language
|
||||
* @param log_interface $log
|
||||
* @param request_interface $request
|
||||
* @param template $template
|
||||
* @param user $user
|
||||
*/
|
||||
public function __construct(config $config, language $language, log_interface $log, request_interface $request, template $template, user $user)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->language = $language;
|
||||
$this->log = $log;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function is_available(): bool
|
||||
|
@ -168,8 +199,55 @@ class turnstile implements plugin_interface
|
|||
// TODO: Implement garbage_collect() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function acp_page($id, $module): void
|
||||
{
|
||||
// TODO: Implement acp_page() method.
|
||||
$captcha_vars = [
|
||||
'captcha_turnstile_sitekey' => 'CAPTCHA_TURNSTILE_SITEKEY',
|
||||
'captcha_turnstile_secret' => 'CAPTCHA_TURNSTILE_SECRET',
|
||||
];
|
||||
|
||||
$module->tpl_name = 'captcha_turnstile_acp';
|
||||
$module->page_title = 'ACP_VC_SETTINGS';
|
||||
$form_key = 'acp_captcha';
|
||||
add_form_key($form_key);
|
||||
|
||||
$submit = $this->request->is_set_post('submit');
|
||||
|
||||
if ($submit && check_form_key($form_key))
|
||||
{
|
||||
$captcha_vars = array_keys($captcha_vars);
|
||||
foreach ($captcha_vars as $captcha_var)
|
||||
{
|
||||
$value = $this->request->variable($captcha_var, '');
|
||||
if ($value)
|
||||
{
|
||||
$this->config->set($captcha_var, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CONFIG_VISUAL');
|
||||
trigger_error($this->language->lang('CONFIG_UPDATED') . adm_back_link($module->u_action));
|
||||
}
|
||||
else if ($submit)
|
||||
{
|
||||
trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($module->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($captcha_vars as $captcha_var => $template_var)
|
||||
{
|
||||
$var = $this->request->is_set($captcha_var) ? $this->request->variable($captcha_var, '') : $this->config->offsetGet($captcha_var);;
|
||||
$this->template->assign_var($template_var, $var);
|
||||
}
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'CAPTCHA_PREVIEW' => $this->get_demo_template(),
|
||||
'CAPTCHA_NAME' => $this->service_name,
|
||||
'U_ACTION' => $module->u_action,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue