1
0
Эх сурвалжийг харах

#136 - Integrate new reCaptcha.

AntonLV 11 жил өмнө
parent
commit
ff6d2ec93a

+ 5 - 0
inc/utils.inc.php

@@ -762,6 +762,11 @@ function bx_file_get_contents($sFileUrl, $aParams = array(), $bChangeTimeout = f
         curl_setopt($rConnect, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($rConnect, CURLOPT_FOLLOWLOCATION, 1);
 
+        if(bx_mb_strpos($sFileUrl, 'https') !== false) {
+	        curl_setopt($rConnect, CURLOPT_SSL_VERIFYPEER, 0);
+			curl_setopt($rConnect, CURLOPT_SSL_VERIFYHOST, 0);
+        }
+
         if ($bChangeTimeout) {
             curl_setopt($rConnect, CURLOPT_CONNECTTIMEOUT, 3);
             curl_setopt($rConnect, CURLOPT_TIMEOUT, 3);

+ 2 - 1
install/sql/system.sql

@@ -74,7 +74,8 @@ CREATE TABLE `sys_objects_captcha` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 INSERT INTO `sys_objects_captcha` (`object`, `title`, `override_class_name`, `override_class_file`) VALUES
-('sys_recaptcha', 'reCAPTCHA', 'BxTemplCaptchaReCAPTCHA', '');
+('sys_recaptcha', 'reCAPTCHA', 'BxTemplCaptchaReCAPTCHA', ''),
+('sys_recaptcha_new', 'reCAPTCHA New', 'BxTemplCaptchaReCAPTCHANew', '');
 
 
 -- --------------------------------------------------------

+ 23 - 0
modules/boonex/lagoon/data/template/system/scripts/BxTemplCaptchaReCAPTCHANew.php

@@ -0,0 +1,23 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+bx_import('BxBaseCaptchaReCAPTCHANew');
+
+/**
+ * @see BxDolCaptcha
+ */
+class BxTemplCaptchaReCAPTCHANew extends BxBaseCaptchaReCAPTCHANew
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 23 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplCaptchaReCAPTCHANew.php

@@ -0,0 +1,23 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+bx_import('BxBaseCaptchaReCAPTCHANew');
+
+/**
+ * @see BxDolCaptcha
+ */
+class BxTemplCaptchaReCAPTCHANew extends BxBaseCaptchaReCAPTCHANew
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 96 - 0
template/scripts/BxBaseCaptchaReCAPTCHANew.php

@@ -0,0 +1,96 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+bx_import('BxTemplCaptchaReCAPTCHA');
+
+/**
+ * reCAPTCHA representation.
+ * @see BxDolCaptcha
+ */
+class BxBaseCaptchaReCAPTCHANew extends BxTemplCaptchaReCAPTCHA
+{
+	protected $sApiUrl;
+	protected $sVerifyUrl;
+
+    public function __construct ($aObject, $oTemplate)
+    {
+        parent::__construct ($aObject, $oTemplate);
+
+        $this->sApiUrl = 'https://www.google.com/recaptcha/api.js';
+        $this->sVerifyUrl = 'https://www.google.com/recaptcha/api/siteverify';
+    }
+
+    /**
+     * Display captcha.
+     */
+    public function display ($bDynamicMode = false)
+    {
+        $sCode = '';
+        $aApiParams = array();
+        if($bDynamicMode)  {
+        	$sPostfix = time() . rand(0, PHP_INT_MAX);
+        	$sId = 'sys-captcha-' . $sPostfix;
+
+        	$sOnLoadFunction = 'onLoadCallback' . $sPostfix;
+        	$sOnLoadCode = "
+	        	var " . $sOnLoadFunction . " = function() {
+					grecaptcha.render('" . $sId . "', {
+						'sitekey': '" . $this->_sKeyPublic . "',
+						'theme': '" . $this->_sSkin . "'
+					});
+				};
+		        ";
+
+        	$aApiParams = array(
+        		'onload' => $sOnLoadFunction,
+        		'render' => 'explicit'
+        	);
+
+        	$sCode .= $this->_oTemplate->_wrapInTagJsCode($sOnLoadCode);
+        	$sCode .= '<div id="' . $sId . '">';
+        }
+        else {
+        	$aApiParams = array(
+        		'render' => 'onload'
+        	);
+
+        	$sCode .= '<div class="g-recaptcha" data-sitekey="' . $this->_sKeyPublic . '" data-theme="' . $this->_sSkin . '"></div>';
+        }
+
+        bx_import('BxDolLanguages');
+        $aApiParams['hl'] = BxDolLanguages::getInstance()->getCurrentLanguage();
+
+        return $this->_oTemplate->addJs(bx_append_url_params($this->sApiUrl, $aApiParams), $bDynamicMode) . $sCode;
+    }
+
+    /**
+     * Check captcha.
+     */
+    public function check ()
+    {
+    	$mixedResponce = bx_file_get_contents($this->sVerifyUrl, array(
+    		'secret' => $this->_sKeyPrivate, 
+    		'response' => bx_process_input(bx_get('g-recaptcha-response')),
+    		'remoteip' => getVisitorIP()
+    	));
+    	if($mixedResponce === false)
+    		return false;
+
+    	$aResponce = json_decode($mixedResponce, true); 	
+    	if(isset($aResponce['success']) && $aResponce['success'] === true)
+    		return true;
+
+		if(!empty($aResponce['error-codes']))
+			$this->_error = $aResponce['error-codes'];
+
+		return false;
+    }
+}
+
+/** @} */