Skip to content

Instantly share code, notes, and snippets.

@sudikrt
Created August 7, 2019 19:32
Show Gist options
  • Save sudikrt/7ab0d5972f3ba258bd22bfe794eca787 to your computer and use it in GitHub Desktop.
Save sudikrt/7ab0d5972f3ba258bd22bfe794eca787 to your computer and use it in GitHub Desktop.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes">
<ltng:require scripts="{!join(',',
$Resource.jQuery_3_1_1)}"
afterScriptsLoaded="{!c.onScriptLoaded}"/>
<aura:attribute name="hasreCaptchaVerified" type="Boolean" default="false" />
<aura:attribute name="hostUrl" type="String" />
<aura:attribute name="recaptchaPageName" type="String" default="apex/reCaptcha"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<div>
<div class="slds-align_absolute-center container">
<lightning:layout horizontalAlign="center" verticalAlign="center" multipleRows="true" class="slds-box outer-box">
<!-- Captcha Section-->
<lightning:layoutItem size="12" class="slds-m-top_small recaptcha-section">
<iframe src="{!v.hostUrl + '/' + v.recaptchaPageName}" frameborder="0" width="100%" allowtransparency="true" id="recaptchaFrame" class="recaptchaFrame "/>
</lightning:layoutItem>
<lightning:layoutItem size="12" class="slds-m-top_small recaptcha-section">
<div class="slds-text-color_error">Is Verified : {!v.hasreCaptchaVerified}</div>
</lightning:layoutItem>
</lightning:layout>
</div>
</div>
</aura:component>
({
onScriptLoaded : function(component, event, helper) {
jQuery(function($){
let iframe = $('.recaptchaFrame');
iframe = iframe[0];
iframe.height = '60px';
});
},
doInit : function(component, event, helper) {
window.addEventListener("message", function(event) {
let hostOrigin = "https://test-dev-ed--foolish.ap5.visual.force.com"; //window.location.origin
if (event.origin !== hostOrigin) {
return;
}
if (event.data && event.data.action && event.data.action === 'verified') {
component.set ('v.hasreCaptchaVerified', true);
} else if (event.data && event.data.action && event.data.action === 'error') {
component.set ('v.hasreCaptchaVerified', false);
} else if (event.data && event.data.action && event.data.action === 'expired') {
component.set ('v.hasreCaptchaVerified', false);
} else if (event.data && event.data.action && event.data.action === 'loaded') {
component.set ('v.hasreCaptchaVerified', false);
}
if (event.data && event.data.action && event.data.action === 'heigthChange') {
let iframe = $('.recaptchaFrame');
iframe = iframe[0];
iframe.height = event.data.height;
}
}, false);
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment