Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
Fix issue #6 + Fix reCaptcha renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Jul 11, 2017
1 parent 3a23b9d commit 5fa25c1
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 30 deletions.
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_ReCaptcha" setup_version="1.0.1">
<module name="MSP_ReCaptcha" setup_version="1.0.2">
<sequence>
<module name="MSP_Common"/>
<module name="MSP_SecuritySuiteCommon"/>
Expand Down
23 changes: 23 additions & 0 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="customer-email" xsi:type="array">
<item name="children" xsi:type="array">
<item name="msp_recaptcha" xsi:type="array">
<item name="component" xsi:type="string">MSP_ReCaptcha/js/reCaptcha</item>
<item name="displayArea" xsi:type="string">additional-login-form-fields</item>
<item name="configSource" xsi:type="string">checkoutConfig</item>
<item name="reCaptchaId" xsi:type="string">msp-recaptcha-checkout-inline-login</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>

<item name="authentication" xsi:type="array">
<item name="children" xsi:type="array">
<item name="msp_recaptcha" xsi:type="array">
Expand Down
28 changes: 28 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@magespecialist.it so we can send you a copy immediately.
*
* @category MSP
* @package MSP_ReCaptcha
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

var config = {
config: {
mixins: {
'Magento_Ui/js/view/messages': {
'MSP_ReCaptcha/js/ui-messages-mixin': true
}
}
}
};
61 changes: 32 additions & 29 deletions view/frontend/web/js/reCaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,38 @@
/*browser:true jquery:true*/
/*global define*/
define(
[
'uiComponent',
'https://www.google.com/recaptcha/api.js'
],
function (Component, reCaptcha) {
'use strict';
[
'uiComponent',
'MSP_ReCaptcha/js/registry',
'https://www.google.com/recaptcha/api.js'
],
function (Component, registry, reCaptcha) {
'use strict';

return Component.extend({
defaults: {
template: 'MSP_ReCaptcha/reCaptcha'
},
getIsVisible: function() {
return window.mspReCaptchaConfig.enabled;
},
getSiteKey: function() {
return window.mspReCaptchaConfig.siteKey;
},
renderReCaptcha: function () {
grecaptcha.render(this.getReCaptchaId(), {
'sitekey': this.getSiteKey()
});
},
getReCaptchaId: function () {
if (!this.reCaptchaId) {
return 'msp-recaptcha';
}
return Component.extend({
defaults: {
template: 'MSP_ReCaptcha/reCaptcha'
},
getIsVisible: function () {
return window.mspReCaptchaConfig.enabled;
},
getSiteKey: function () {
return window.mspReCaptchaConfig.siteKey;
},
renderReCaptcha: function () {
registry.ids.push(this.getReCaptchaId());

return this.reCaptchaId;
}
});
}
registry.captchaList.push(grecaptcha.render(this.getReCaptchaId(), {
'sitekey': this.getSiteKey()
}));
},
getReCaptchaId: function () {
if (!this.reCaptchaId) {
return 'msp-recaptcha';
}

return this.reCaptchaId;
}
});
}
);
27 changes: 27 additions & 0 deletions view/frontend/web/js/registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@magespecialist.it so we can send you a copy immediately.
*
* @category MSP
* @package MSP_ReCaptcha
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

define(['ko'], function (ko) {
'use strict';

return {
ids: ko.observableArray([]),
captchaList: ko.observableArray([])
};
});
40 changes: 40 additions & 0 deletions view/frontend/web/js/ui-messages-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@magespecialist.it so we can send you a copy immediately.
*
* @category MSP
* @package MSP_ReCaptcha
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

define(['MSP_ReCaptcha/js/registry'], function (registry) {
'use strict';

return function (originalComponent) {
'use strict';

return originalComponent.extend({
initialize: function () {
this._super();

this.messageContainer.errorMessages.subscribe(function (newValue) {
registry.captchaList().forEach(function (captcha) {
grecaptcha.reset(captcha);
});
}, null, "arrayChange");

return this;
}
});
};
});

0 comments on commit 5fa25c1

Please sign in to comment.