Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,36 +11,46 @@
|
||||
namespace IPS\Helpers\Form\Captcha;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Http\Url;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
use function mb_strlen;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* hCaptcha
|
||||
*/
|
||||
class _Hcaptcha implements CaptchaInterface
|
||||
class Hcaptcha implements CaptchaInterface
|
||||
{
|
||||
/**
|
||||
* Does this CAPTCHA service support being added in a modal?
|
||||
*/
|
||||
public static $supportsModal = FALSE;
|
||||
public static bool $supportsModal = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Error
|
||||
*/
|
||||
protected $error;
|
||||
protected ?string $error;
|
||||
|
||||
/**
|
||||
* Display
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHtml()
|
||||
public function getHtml(): string
|
||||
{
|
||||
\IPS\Output::i()->jsFilesAsync[] = "https://js.hcaptcha.com/1/api.js";
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->hCaptcha( \IPS\Settings::i()->hcaptcha_sitekey );
|
||||
Output::i()->jsFilesAsync[] = "https://js.hcaptcha.com/1/api.js";
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->hCaptcha( Settings::i()->hcaptcha_sitekey );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,20 +58,20 @@ class _Hcaptcha implements CaptchaInterface
|
||||
*
|
||||
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
|
||||
*/
|
||||
public function verify()
|
||||
public function verify(): ?bool
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( 'https://hcaptcha.com/siteverify' )->request()->post( array(
|
||||
'secret' => \IPS\Settings::i()->hcaptcha_secret,
|
||||
'response' => trim( \IPS\Request::i()->__get('h-captcha-response') ),
|
||||
'remoteip' => \IPS\Request::i()->ipAddress(),
|
||||
) )->decodeJson( TRUE );
|
||||
$response = Url::external( 'https://hcaptcha.com/siteverify' )->request()->post( array(
|
||||
'secret' => Settings::i()->hcaptcha_secret,
|
||||
'response' => trim( Request::i()->__get('h-captcha-response') ),
|
||||
'remoteip' => Request::i()->ipAddress(),
|
||||
) )->decodeJson();
|
||||
|
||||
$hostname = \IPS\Http\Url::internal('')->data[ \IPS\Http\Url::COMPONENT_HOST ];
|
||||
return ( ( (bool) $response['success'] ) and ( $response['hostname'] === mb_substr( $hostname, \mb_strlen( $hostname ) - mb_strlen( $response['hostname'] ) ) ) );
|
||||
$hostname = Url::internal('')->data[ Url::COMPONENT_HOST ];
|
||||
return ( ( $response['success'] ) and ( $response['hostname'] === mb_substr( $hostname, mb_strlen( $hostname ) - mb_strlen( $response['hostname'] ) ) ) );
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
catch( RuntimeException $e )
|
||||
{
|
||||
if( $e->getMessage() == 'BAD_JSON' )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user