feat: captcha protection for ep-events

This commit is contained in:
Björn Fromme
2024-08-19 11:11:09 +02:00
parent e6c4948644
commit e2bc3f72da
14 changed files with 200 additions and 64 deletions
@@ -136,8 +136,7 @@ class AjaxFormController extends ActionController implements LoggerAwareInterfac
];
if ($this->arguments->validate()->hasErrors()) {
foreach ($this->arguments->validate()->getFlattenedErrors() as $key => $errors)
{
foreach ($this->arguments->validate()->getFlattenedErrors() as $key => $errors) {
$key = str_replace('.', '', $key);
$errorsRaw = [];
foreach ($errors as $error)
@@ -33,6 +33,13 @@ class Inquiry extends AbstractValueObject
{
public const TOKEN_KEY = 'inquiry_form';
/**
* @var string
*
* @TYPO3\CMS\Extbase\Annotation\Validate("SJBR\SrFreecap\Validation\Validator\CaptchaValidator")
*/
protected $captchaResponse;
/**
* @var string
*/
@@ -226,6 +233,22 @@ class Inquiry extends AbstractValueObject
$this->token = $token;
}
/**
* @return string
*/
public function getCaptchaResponse()
{
return $this->captchaResponse;
}
/**
* @param string $captchaResponse
*/
public function setCaptchaResponse(string $captchaResponse)
{
$this->captchaResponse = $captchaResponse;
}
/**
* @return string
*/
@@ -0,0 +1 @@
@import 'EXT:sr_freecap/Configuration/TypoScript/setup.typoscript'
@@ -68,3 +68,4 @@ plugin.tx_epevents {
@import 'EXT:fluid_styled_content/Configuration/TypoScript/constants.typoscript'
@import 'EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'
@import 'EXT:news/Configuration/TypoScript/constants.txt'
@import 'EXT:sr_freecap/Configuration/TypoScript/constants.typoscript'
@@ -160,6 +160,7 @@
this.processing = false;
if (response.status === 'validation') {
this.formErrors = response.errors;
$('.tx-srfreecap-cant-read > a').click();
} else {
this.success = true;
this.$session.remove('formData');
@@ -38,6 +38,7 @@
this.processing = false;
if (response.status === 'validation') {
this.formErrors = response.errors;
$('.tx-srfreecap-cant-read > a').click();
} else {
this.success = true;
this.trackConversion();
@@ -88,6 +88,7 @@
.form__item__error {
padding: 8px;
font-size: 90%;
color: $color-formerror;
}
.form__field {
@@ -252,3 +253,12 @@
color: white;
}
}
.tx-srfreecap-cant-read {
color: white;
font-size: 80%;
}
img.tx-srfreecap-image {
margin: 0 16px 16px 0;
}
@@ -91,6 +91,9 @@
<trans-unit id="tx_epevents.message.email.1221559976">
<target>Ungültige E-Mail Adresse</target>
</trans-unit>
<trans-unit id="tx_epevents.message.captchaResponse.9221561048">
<target>Die eingegebenen Zeichen stimmen nicht mit der Grafik überein</target>
</trans-unit>
<trans-unit id="tx_epevents_domain_model_traveltype">
<target>Reiseart</target>
</trans-unit>
@@ -106,6 +109,9 @@
<trans-unit id="tx_epevents.message.inquiryemail.1221559976">
<target>Ungültige E-Mail Adresse</target>
</trans-unit>
<trans-unit id="tx_epevents.message.inquirycaptchaResponse.9221561048">
<target>Die eingegebenen Zeichen stimmen nicht mit der Grafik überein</target>
</trans-unit>
<trans-unit id="tx_epevents.label.ask_our_expert">
<target>Frag unseren Profi</target>
</trans-unit>
@@ -91,6 +91,9 @@
<trans-unit id="tx_epevents.message.email.1221559976">
<source>The email address is invalid</source>
</trans-unit>
<trans-unit id="tx_epevents.message.captchaResponse.9221561048">
<source>The entered characters dont match</source>
</trans-unit>
<trans-unit id="tx_epevents_domain_model_traveltype">
<source>Type of travel</source>
</trans-unit>
@@ -106,6 +109,9 @@
<trans-unit id="tx_epevents.message.inquiryemail.1221559976">
<source>The email address is invalid</source>
</trans-unit>
<trans-unit id="tx_epevents.message.inquirycaptchaResponse.9221561048">
<source>The entered characters dont match</source>
</trans-unit>
<trans-unit id="tx_epevents.label.ask_our_expert">
<source>Ask our expert</source>
</trans-unit>
@@ -1,6 +1,7 @@
<html data-namespace-typo3-fluid="true" lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
xmlns:freeCap="http://typo3.org/ns/SJBR/SrFreecap/ViewHelpers"
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">
<f:layout name="Default"/>
@@ -169,7 +170,7 @@
</div>
<div class="form__item form__item--button form__item--tablet">
<button class="button button--configurator"
@click.prevent="submitForm">&raquo; {f:translate(key: 'tx_epevents.label.inquire_now', extensionName: 'ep_events') -> f:format.raw())}</button>
@click.prevent="submitForm">&raquo; {f:translate(key: 'tx_epevents.label.inquire_now', extensionName: 'ep_events') -> f:format.raw()}</button>
</div>
<f:if condition="{settings.feedbackPageUid}">
<div class="form__item form__item--link form__item--tablet">
@@ -210,6 +211,20 @@
placeholder="{f:translate(key: 'tx_epevents.label.contact_form_message', extensionName: 'ep_events') -> f:format.raw()}"
additionalAttributes="{v-model: 'formData.message'}"/>
</div>
<div class="form__item">
<span class="form__text">Bitte geben Sie die Zeichen aus der nachfolgenden Grafik ein.</span>
</div>
<div class="form__item" :class="{ 'has-errors': formErrors.inquirycaptchaResponse }">
<f:form.textfield class="form__field form__field--configurator form__field--text"
property="captchaResponse" size="15"
placeholder="Spamschutz"
additionalAttributes="{v-model: 'formData.captchaResponse'}"
title="{freeCap:translate(key: 'notice')}{freeCap:translate(key: 'explain')}" />
<div class="form__item__error" v-show="formErrors.inquirycaptchaResponse" v-html="formErrors.inquirycaptchaResponse"></div>
</div>
<div class="form__item">
<freeCap:image />
</div>
<div class="form__item form__item--mobile">
<span class="form__text">
{f:translate(key: 'tx_epevents.label.privacy_text', arguments: '{0: \'{f:uri.typolink(parameter: settings.dataProtectionPageUid)}\'}', extensionName: 'ep_events') -> f:format.raw()}
@@ -1,6 +1,7 @@
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"
xmlns:freeCap="http://typo3.org/ns/SJBR/SrFreecap/ViewHelpers"
xmlns:ep="http://typo3.org/ns/EP/EpEvents/ViewHelpers">
<f:layout name="Default"/>
@@ -92,6 +93,20 @@
placeholder="{f:translate(key: 'tx_epevents.label.contact_form_message', extensionName: 'ep_events') -> f:format.raw()}"
additionalAttributes="{v-model: 'formData.message'}"/>
</div>
<div class="form__item">
<f:form.textfield class="form__field form__field--text"
property="captchaResponse" size="15"
placeholder="Spamschutz"
additionalAttributes="{v-model: 'formData.captchaResponse'}"
title="{freeCap:translate(key: 'notice')}{freeCap:translate(key: 'explain')}" />
<div class="form__item__error" v-show="formErrors.inquirycaptchaResponse" v-html="formErrors.inquirycaptchaResponse"></div>
</div>
<div class="form__item form__item--text">
<span class="form__text">Bitte geben Sie die Zeichen aus der nachfolgenden Grafik ein.</span>
</div>
<div class="form__item">
<freeCap:image />
</div>
<div class="form__item">
<span class="form__text">{f:translate(key: 'tx_epevents.label.privacy_text', arguments: '{0: \'{f:uri.typolink(parameter: settings.dataProtectionPageUid)}\'}', extensionName: 'ep_events') -> f:format.raw()}</span>
</div>
@@ -1,5 +1,6 @@
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"
xmlns:freeCap="http://typo3.org/ns/SJBR/SrFreecap/ViewHelpers"
xmlns:ep="http://typo3.org/ns/EP/EpEvents/ViewHelpers">
<f:layout name="Default"/>
@@ -78,6 +79,20 @@
placeholder="{f:translate(key: 'tx_epevents.label.contact_form_message', extensionName: 'ep_events') -> f:format.raw()}"
additionalAttributes="{v-model: 'formData.message'}"/>
</div>
<div class="form__item">
<f:form.textfield class="form__field form__field--text"
property="captchaResponse" size="15"
placeholder="Spamschutz"
additionalAttributes="{v-model: 'formData.captchaResponse'}"
title="{freeCap:translate(key: 'notice')}{freeCap:translate(key: 'explain')}" />
<div class="form__item__error" v-show="formErrors.inquirycaptchaResponse" v-html="formErrors.inquirycaptchaResponse"></div>
</div>
<div class="form__item form__item--text">
<span class="form__text">Bitte geben Sie die Zeichen aus der nachfolgenden Grafik ein.</span>
</div>
<div class="form__item">
<freeCap:image />
</div>
<div class="form__item">
<span class="form__text">{f:translate(key: 'tx_epevents.label.privacy_text', arguments: '{0: \'{f:uri.typolink(parameter: settings.dataProtectionPageUid)}\'}', extensionName: 'ep_events') -> f:format.raw()}</span>
</div>