diff --git a/Block/Captcha.php b/Block/Captcha.php index 7dfbed4..a9c3e23 100644 --- a/Block/Captcha.php +++ b/Block/Captcha.php @@ -92,6 +92,7 @@ public function __construct( public function getForms() { $useLogin = false; + $ageVerification = false; $this->_dataFormId = $this->_helperData->getFormsFrontend(); foreach ($this->_dataFormId as $item => $value) { @@ -112,10 +113,11 @@ public function getForms() case Forms::TYPE_PRODUCTREVIEW: $actionName = $this->actionName[4]; break; - case Forms::TYPE_CHANGEPASSWORD: + case Forms::TYPE_EDITACCOUNT: $actionName = $this->actionName[5]; break; default: + $ageVerification = true; $actionName = ''; } $this->unsetDataFromId($item, $actionName); @@ -127,7 +129,7 @@ public function getForms() } } - if ($this->isAgeVerificationEnabled()) { + if ($this->isAgeVerificationEnabled() && $ageVerification) { $this->_dataFormId[] = Forms::TYPE_AGEVERIFICATION; } diff --git a/Helper/Data.php b/Helper/Data.php index 733c675..c7b3f05 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -24,6 +24,7 @@ use Exception; use Magento\Checkout\Helper\Data as CheckoutData; use Magento\Framework\App\Helper\Context; +use Magento\Framework\Encryption\EncryptorInterface; use Magento\Framework\HTTP\Adapter\CurlFactory; use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\StoreManagerInterface; @@ -51,6 +52,11 @@ class Data extends CoreHelper */ protected $_formPaths; + /** + * @var EncryptorInterface + */ + protected $encryptor; + /** * Data constructor. * @@ -59,16 +65,19 @@ class Data extends CoreHelper * @param StoreManagerInterface $storeManager * @param CurlFactory $curlFactory * @param DefaultFormsPaths $formPaths + * @param EncryptorInterface $encryptor */ public function __construct( Context $context, ObjectManagerInterface $objectManager, StoreManagerInterface $storeManager, CurlFactory $curlFactory, - DefaultFormsPaths $formPaths + DefaultFormsPaths $formPaths, + EncryptorInterface $encryptor ) { $this->_curlFactory = $curlFactory; $this->_formPaths = $formPaths; + $this->encryptor = $encryptor; parent::__construct($context, $objectManager, $storeManager); } @@ -84,7 +93,7 @@ public function __construct( */ public function getVisibleKey($storeId = null) { - return $this->getConfigGeneral('visible/api_key', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('visible/api_key', $storeId)); } /** @@ -94,7 +103,7 @@ public function getVisibleKey($storeId = null) */ public function getVisibleSecretKey($storeId = null) { - return $this->getConfigGeneral('visible/api_secret', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('visible/api_secret', $storeId)); } /** @@ -226,7 +235,7 @@ public function getFormsFrontend($storeId = null) */ public function getInvisibleKey($storeId = null) { - return $this->getConfigGeneral('invisible/api_key', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('invisible/api_key', $storeId)); } /** @@ -236,7 +245,7 @@ public function getInvisibleKey($storeId = null) */ public function getInvisibleSecretKey($storeId = null) { - return $this->getConfigGeneral('invisible/api_secret', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('invisible/api_secret', $storeId)); } /** diff --git a/Model/System/Config/Source/Frontend/Forms.php b/Model/System/Config/Source/Frontend/Forms.php index 13d11a3..91a64a8 100644 --- a/Model/System/Config/Source/Frontend/Forms.php +++ b/Model/System/Config/Source/Frontend/Forms.php @@ -34,7 +34,7 @@ class Forms implements ArrayInterface const TYPE_CREATE = 'body.customer-account-create #form-validate.form-create-account'; const TYPE_FORGOT = '#form-validate.form.password.forget'; const TYPE_CONTACT = '#contact-form'; - const TYPE_CHANGEPASSWORD = '#form-validate.form.form-edit-account'; + const TYPE_EDITACCOUNT = '#form-validate.form.form-edit-account'; const TYPE_PRODUCTREVIEW = '#review-form'; const TYPE_AGEVERIFICATION = '#mpageverify-form'; const TYPE_FORMSEXTENDED = [ @@ -84,7 +84,7 @@ public function getOptionHash() self::TYPE_CREATE => __('Create User'), self::TYPE_FORGOT => __('Forgot Password'), self::TYPE_CONTACT => __('Contact Us'), - self::TYPE_CHANGEPASSWORD => __('Change Password'), + self::TYPE_EDITACCOUNT => __('Edit Account'), self::TYPE_PRODUCTREVIEW => __('Product Review') ]; if ($this->checkModuleEnable('Mageplaza_AgeVerification')) { @@ -104,7 +104,7 @@ public function defaultForms() self::TYPE_CREATE => 'customer/account/createpost/', self::TYPE_FORGOT => 'customer/account/forgotpasswordpost/', self::TYPE_CONTACT => 'contact/index/post/', - self::TYPE_CHANGEPASSWORD => 'customer/account/editPost/', + self::TYPE_EDITACCOUNT => 'customer/account/editPost/', self::TYPE_PRODUCTREVIEW => 'review/product/post/' ]; if ($this->checkModuleEnable('Mageplaza_AgeVerification')) { diff --git a/Observer/Adminhtml/Forgot.php b/Observer/Adminhtml/Forgot.php index 0c5520a..bf7b47a 100644 --- a/Observer/Adminhtml/Forgot.php +++ b/Observer/Adminhtml/Forgot.php @@ -103,7 +103,8 @@ public function execute(Observer $observer) { if ($this->_helperData->isCaptchaBackend() && $this->_request->getParam('g-recaptcha-response') !== null - && in_array('backend_forgotpassword', $this->_helperData->getFormsBackend(), true) + && (in_array('backend_forgotpassword', $this->_helperData->getFormsBackend(), true)) + && ($this->_helperData->getVisibleKey() !== null && $this->_helperData->getVisibleSecretKey() !== null) ) { $controller = $this->_urlInterface->getCurrentUrl(); try { diff --git a/Observer/Adminhtml/Login.php b/Observer/Adminhtml/Login.php index 4643372..bf232d6 100644 --- a/Observer/Adminhtml/Login.php +++ b/Observer/Adminhtml/Login.php @@ -57,7 +57,8 @@ public function __construct( public function execute(Observer $observer) { if ($this->_helperData->isCaptchaBackend() - && in_array('backend_login', $this->_helperData->getFormsBackend(), true) + && (in_array('backend_login', $this->_helperData->getFormsBackend(), true)) + && ($this->_helperData->getVisibleKey() !== null && $this->_helperData->getVisibleSecretKey() !== null) ) { $response = $this->_helperData->verifyResponse('visible'); if (!array_key_exists('success', $response) || empty($response['success'])) { diff --git a/README.md b/README.md index 4abe501..088af64 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,21 @@ A: Yes, you can choose a language code to display reCAPTCHA on the backend. Run the following command in Magento 2 root folder: +With Marketing Automation (recommend): + +``` +composer require mageplaza/module-google-recaptcha mageplaza/module-smtp +php bin/magento setup:upgrade +php bin/magento setup:static-content:deploy +``` + +Without Marketing Automation: ``` composer require mageplaza/module-google-recaptcha php bin/magento setup:upgrade php bin/magento setup:static-content:deploy ``` + ## 4. Google reCAPTCHA highlight features ### Invisible reCAPTCHA diff --git a/composer.json b/composer.json index 1ddb209..b8c07df 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "google/recaptcha": "^1.2" }, "type": "magento2-module", - "version": "1.2.2", + "version": "1.2.3", "license": "proprietary", "authors": [ { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c617919..83b8ab3 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -32,25 +32,32 @@ Magento\Config\Model\Config\Source\Yesno + One Step Checkout.
+ 1. Increase 25% conversion rate with Layered Navigation
+ 2. Magento stores see upwards of 30% revenue 💰 with AVADA. Learn more]]>
- + + Magento\Config\Model\Config\Backend\Encrypted here.]]> - + + Magento\Config\Model\Config\Backend\Encrypted - + + Magento\Config\Model\Config\Backend\Encrypted here.]]> - + + Magento\Config\Model\Config\Backend\Encrypted diff --git a/view/frontend/web/js/captcha.js b/view/frontend/web/js/captcha.js index 4fcc597..c9552fe 100644 --- a/view/frontend/web/js/captcha.js +++ b/view/frontend/web/js/captcha.js @@ -88,6 +88,9 @@ define([ && $(element).prop("tagName").toLowerCase() === 'form') { self.activeForm.push(element); result = true; + } else if (element === '.opc-wrapper.one-step-checkout-wrapper') { + self.activeForm.push(element); + result = true; } }); } @@ -108,7 +111,7 @@ define([ var divCaptcha = $('
'); var divAction = $('.actions-toolbar'); var divError = $('
'); - var checkBox = $(''); + var checkBox = $(''); divError.text($t('You need select captcha')).attr('style', 'display:none;color:red'); divCaptcha.attr('id', 'mp' + '_recaptcha_' + number); @@ -143,6 +146,7 @@ define([ || value === '#social-form-create' || value === '#social-form-password-forget' || value === '.popup-authentication #login-form.form.form-login' + || value === '.opc-wrapper.one-step-checkout-wrapper' || (value === '#review-form' && self.options.type === 'invisible') ) { buttonElement.trigger('click'); @@ -182,8 +186,26 @@ define([ || value === '#social-form-create' || value === '#social-form-password-forget' || value === '.popup-authentication #login-form.form.form-login' + || value === '.opc-wrapper.one-step-checkout-wrapper' || (value === '#review-form' && self.options.type === 'invisible') ) { + if (value === '.opc-wrapper.one-step-checkout-wrapper') { + $('button.checkout').on('click', function (event) { + if (!self.stopSubmit) { + $.each(self.captchaForm, function (form, value) { + if (element.find('#' + value).length > 0) { + grecaptcha.reset(form); + grecaptcha.execute(form); + resetForm = form; + event.preventDefault(event); + event.stopImmediatePropagation(); + + return false; + } + }); + } + }); + } buttonElement.on('click', function (event) { if (!(element.validation() && element.validation('isValid'))) { return; @@ -256,6 +278,7 @@ define([ $.each(self.captchaForm, function (form, value) { if (element.find('#' + value).length > 0) { self.showMessage(divError, 5000); + buttonElement.attr('disabled', false); grecaptcha.reset(form); event.preventDefault(event); event.stopImmediatePropagation();