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,35 +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\Request\Exception;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Log;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* reCAPTCHA
|
||||
*/
|
||||
class _Recaptcha2 implements CaptchaInterface
|
||||
class Recaptcha2 implements CaptchaInterface
|
||||
{
|
||||
/**
|
||||
* Does this CAPTCHA service support being added in a modal?
|
||||
*/
|
||||
public static $supportsModal = TRUE;
|
||||
public static bool $supportsModal = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Error
|
||||
*/
|
||||
protected $error;
|
||||
protected ?string $error;
|
||||
|
||||
/**
|
||||
* Display
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHtml()
|
||||
public function getHtml(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaRecaptcha2( \IPS\Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', \IPS\Member::loggedIn()->language()->short ), \IPS\Theme::i()->settings['recaptcha2_theme'] );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaRecaptcha2( Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', Member::loggedIn()->language()->short ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,25 +58,25 @@ class _Recaptcha2 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://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
|
||||
'secret' => \IPS\Settings::i()->recaptcha2_private_key,
|
||||
'response' => trim( \IPS\Request::i()->__get('g-recaptcha-response') ),
|
||||
'remoteip' => \IPS\Request::i()->ipAddress(),
|
||||
) )->decodeJson( TRUE );
|
||||
$response = Url::external( 'https://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
|
||||
'secret' => Settings::i()->recaptcha2_private_key,
|
||||
'response' => trim( Request::i()->__get('g-recaptcha-response') ),
|
||||
'remoteip' => Request::i()->ipAddress(),
|
||||
) )->decodeJson();
|
||||
|
||||
return ( ( (bool) $response['success'] ) and ( $response['hostname'] === \IPS\Http\Url::internal('')->data[ \IPS\Http\Url::COMPONENT_HOST ] ) );
|
||||
return ( ( $response['success'] ) and ( $response['hostname'] === Url::internal('')->data[ Url::COMPONENT_HOST ] ) );
|
||||
}
|
||||
catch( \IPS\Http\Request\Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'recaptcha2_exception' );
|
||||
Log::log( $e, 'recaptcha2_exception' );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
catch( RuntimeException $e )
|
||||
{
|
||||
if( $e->getMessage() == 'BAD_JSON' )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user