Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8027 added new Captcha provider #5571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
currentTimezone,
unescapeHTML,
getStringFromComponentPath,
searchComponents,
convertStringToHTMLElement,
getArrayFromComponentPath
} from './utils/utils';
Expand Down Expand Up @@ -654,7 +653,7 @@ export default class Webform extends NestedDataComponent {
const rebuild = this.rebuild() || Promise.resolve();
return rebuild.then(() => {
this.emit('formLoad', form);
this.triggerRecaptcha();
this.triggerCaptcha();
// Make sure to trigger onChange after a render event occurs to speed up form rendering.
setTimeout(() => {
this.onChange(flags);
Expand Down Expand Up @@ -1624,16 +1623,20 @@ export default class Webform extends NestedDataComponent {
}
}

triggerRecaptcha() {
triggerCaptcha() {
if (!this || !this.components) {
return;
}
const recaptchaComponent = searchComponents(this.components, {
'component.type': 'recaptcha',
'component.eventType': 'formLoad'

const captchaComponent = [];
eachComponent(this.components, (component) => {
if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
captchaComponent.push(component);
}
});
if (recaptchaComponent.length > 0) {
recaptchaComponent[0].verify(`${this.form.name ? this.form.name : 'form'}Load`);

if (captchaComponent.length > 0) {
captchaComponent[0].verify(`${this.form.name ? this.form.name : 'form'}Load`);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ export default class WebformBuilder extends Component {

attach(element) {
this.on('change', (form) => {
this.populateRecaptchaSettings(form);
this.populateCaptchaSettings(form);
this.webform.setAlert(false);
});
return super.attach(element).then(() => {
Expand Down Expand Up @@ -1080,24 +1080,24 @@ export default class WebformBuilder extends Component {
return Promise.resolve(form);
}

populateRecaptchaSettings(form) {
//populate isEnabled for recaptcha form settings
let isRecaptchaEnabled = false;
populateCaptchaSettings(form) {
//populate isEnabled for captcha form settings
let isCaptchaEnabled = false;
if (this.form.components) {
eachComponent(form.components, component => {
if (isRecaptchaEnabled) {
if (isCaptchaEnabled) {
return;
}
if (component.type === 'recaptcha') {
isRecaptchaEnabled = true;
if (component.type === 'captcha') {
isCaptchaEnabled = true;
return false;
}
});
if (isRecaptchaEnabled) {
_.set(form, 'settings.recaptcha.isEnabled', true);
if (isCaptchaEnabled) {
_.set(form, 'settings.captcha.isEnabled', true);
}
else if (_.get(form, 'settings.recaptcha.isEnabled')) {
_.set(form, 'settings.recaptcha.isEnabled', false);
else if (_.get(form, 'settings.captcha.isEnabled')) {
_.set(form, 'settings.captcha.isEnabled', false);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default class ButtonComponent extends Field {
}

onClick(event) {
this.triggerReCaptcha();
this.triggerCaptcha();
// Don't click if disabled or in builder mode.
if (this.disabled || this.options.attachMode === 'builder') {
return;
Expand Down Expand Up @@ -504,23 +504,23 @@ export default class ButtonComponent extends Field {
}
}

triggerReCaptcha() {
triggerCaptcha() {
if (!this.root) {
return;
}

let recaptchaComponent;
let captchaComponent;

this.root.everyComponent((component)=> {
if ( component.component.type === 'recaptcha' &&
if (/^(re)?captcha$/.test(component.component.type) &&
component.component.eventType === 'buttonClick' &&
component.component.buttonKey === this.component.key) {
recaptchaComponent = component;
captchaComponent = component;
}
});

if (recaptchaComponent) {
recaptchaComponent.verify(`${this.component.key}Click`);
if (captchaComponent) {
captchaComponent.verify(`${this.component.key}Click`);
}
}
}
4 changes: 2 additions & 2 deletions src/components/recaptcha/ReCaptcha.form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Components from '../Components';
import ReCaptchaEditDisplay from './editForm/ReCaptcha.edit.display';

export default function() {
export default function(...extend) {
return Components.baseEditForm([
{
key: 'display',
Expand All @@ -23,5 +23,5 @@ export default function() {
key: 'logic',
ignore: true
},
]);
], ...extend);
}
9 changes: 1 addition & 8 deletions src/components/recaptcha/ReCaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ export default class ReCaptchaComponent extends Component {
}

static get builderInfo() {
return {
title: 'reCAPTCHA',
group: 'premium',
icon: 'refresh',
documentation: '/userguide/form-building/premium-components#recaptcha',
weight: 40,
schema: ReCaptchaComponent.schema()
};
return {};
}

static savedValueTypes() {
Expand Down
12 changes: 10 additions & 2 deletions src/components/recaptcha/editForm/ReCaptcha.edit.display.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { getContextButtons } from '../../../utils/utils';
export default [
{
key: 'recaptchaInfo',
weight: -10,
type: 'htmlelement',
tag: 'div',
className: 'alert alert-danger',
content: 'This component has been deprecated and will be removed. Use the CAPTCHA component instead.',
},
{
key: 'eventType',
label: 'Type of event',
tooltip: 'Specify type of event that this reCAPTCHA would react to',
tooltip: 'Specify type of event that this CAPTCHA would react to. If Button Click is selected, then the CAPTCHA widget will be displayed and verification will occur after clicking on the button.',
type: 'radio',
values: [
{
Expand All @@ -24,7 +32,7 @@ export default [
key: 'buttonKey',
dataSrc: 'custom',
valueProperty: 'value',
tooltip: 'Specify key of button on this form that this reCAPTCHA should react to',
tooltip: 'Specify key of button on this form that this CAPTCHA should react to',
weight: 660,
customConditional(context) {
return context.data.eventType === 'buttonClick';
Expand Down
Loading