mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-12 19:54:12 +02:00
[ticket/17414] Extend plugin interface and wrapper
PHPBB-17414
This commit is contained in:
@@ -17,6 +17,8 @@ class legacy_wrapper implements plugin_interface
|
||||
{
|
||||
private $legacy_captcha;
|
||||
|
||||
private string $last_error;
|
||||
|
||||
public function __construct($legacy_captcha)
|
||||
{
|
||||
$this->legacy_captcha = $legacy_captcha;
|
||||
@@ -72,11 +74,69 @@ class legacy_wrapper implements plugin_interface
|
||||
* @param int $type Type of captcha, should be one of the CONFIRMATION_* constants
|
||||
* @return void
|
||||
*/
|
||||
public function show(int $type): void
|
||||
public function init(int $type): void
|
||||
{
|
||||
if (method_exists($this->legacy_captcha, 'init'))
|
||||
{
|
||||
$this->legacy_captcha->init($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function validate(array $request_data): bool
|
||||
{
|
||||
if (method_exists($this->legacy_captcha, 'validate'))
|
||||
{
|
||||
$error = $this->legacy_captcha->validate($request_data);
|
||||
if ($error)
|
||||
{
|
||||
$this->last_error = $error;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function is_solved(): bool
|
||||
{
|
||||
if (method_exists($this->legacy_captcha, 'is_solved'))
|
||||
{
|
||||
return $this->legacy_captcha->is_solved();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reset(): void
|
||||
{
|
||||
if (method_exists($this->legacy_captcha, 'reset'))
|
||||
{
|
||||
$this->legacy_captcha->reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_attempt_count(): int
|
||||
{
|
||||
if (method_exists($this->legacy_captcha, 'get_attempt_count'))
|
||||
{
|
||||
return $this->legacy_captcha->get_attempt_count();
|
||||
}
|
||||
|
||||
// Ensure this is deemed as too many attempts
|
||||
return PHP_INT_MAX;
|
||||
}
|
||||
}
|
||||
|
@@ -15,16 +15,17 @@ namespace phpbb\captcha\plugins;
|
||||
|
||||
interface plugin_interface
|
||||
{
|
||||
const CONFIRMATION_REGISTRATION = 1;
|
||||
const CONFIRMATION_LOGIN = 2;
|
||||
const CONFIRM_REGISTRATION = 1;
|
||||
const CONFIRM_LOGIN = 2;
|
||||
|
||||
const CONFIRMATION_POST = 3;
|
||||
const CONFIRM_POST = 3;
|
||||
|
||||
const CONFIRMATION_REPORT = 4;
|
||||
const CONFIRM_REPORT = 4;
|
||||
|
||||
|
||||
/**
|
||||
* Check if the plugin is available
|
||||
*
|
||||
* @return bool True if the plugin is available, false if not
|
||||
*/
|
||||
public function is_available(): bool;
|
||||
@@ -49,5 +50,34 @@ interface plugin_interface
|
||||
* @param int $type Type of captcha, should be one of the CONFIRMATION_* constants
|
||||
* @return void
|
||||
*/
|
||||
public function show(int $type): void;
|
||||
public function init(int $type): void;
|
||||
|
||||
/**
|
||||
* Validate the captcha with the given request data
|
||||
*
|
||||
* @param array $request_data Request data for the captcha
|
||||
* @return bool True if request data was valid captcha reply, false if not
|
||||
*/
|
||||
public function validate(array $request_data): bool;
|
||||
|
||||
/**
|
||||
* Return whether captcha was solved
|
||||
*
|
||||
* @return bool True if captcha was solved, false if not
|
||||
*/
|
||||
public function is_solved(): bool;
|
||||
|
||||
/**
|
||||
* Reset captcha state, e.g. after checking if it's valid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset(): void;
|
||||
|
||||
/**
|
||||
* Get attempt count for this captcha and user
|
||||
*
|
||||
* @return int Number of attempts
|
||||
*/
|
||||
public function get_attempt_count(): int;
|
||||
}
|
||||
|
Reference in New Issue
Block a user