Skip to content

Commit

Permalink
Merge branch 'release/14.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
garbast committed Oct 12, 2024
2 parents a50ea50 + 78eb13a commit 9e7c6dc
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 108 deletions.
1 change: 1 addition & 0 deletions Classes/Adapter/SfRegisterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(protected CaptchaService $captchaService, protected
*/
public function render(): array|string
{
$this->session->initializeUserSessionManager();
$this->session->remove('captchaWasValid');
return $this->captchaService->getReCaptcha();
}
Expand Down
7 changes: 6 additions & 1 deletion Classes/Services/CaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ public function validateReCaptcha(string $value = ''): array
];
}

$privateKey = $this->getRequest()->getParsedBody()['recaptcha-invisible'] ?? false
? $this->configuration['invisible_private_key']
: $this->configuration['private_key'];
$privateKey = $privateKey ?: $this->configuration['private_key'];

$request = [
'secret' => $this->configuration['private_key'] ?? '',
'secret' => $privateKey,
'response' => trim(
!empty($value) ? $value : (string)($this->getRequest()->getParsedBody()['g-recaptcha-response'] ?? '')
),
Expand Down
70 changes: 70 additions & 0 deletions Configuration/Sets/Recaptcha/labels.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="EXT:fluid_styled_content/Configuration/Sets/FluidStyledContent/labels.xlf" date="2024-09-05T08:00:00Z" product-name="fluid_styled_content">
<header/>
<body>
<trans-unit id="label" resname="label">
<source>reCAPTCHA</source>
</trans-unit>

<trans-unit id="categories.recaptcha" resname="categories.recaptcha">
<source>reCAPTCHA</source>
</trans-unit>

<trans-unit id="settings.evoweb.recaptcha.apiServer" resname="settings.evoweb.recaptcha.apiServer">
<source>API-server address</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.apiServer" resname="settings.description.evoweb.recaptcha.apiServer">
<source>API Url</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.verifyServer" resname="settings.evoweb.recaptcha.verifyServer">
<source>VERIFY-server address</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.verifyServer" resname="settings.description.evoweb.recaptcha.verifyServer">
<source>Verify Url</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.publicKey" resname="settings.evoweb.recaptcha.publicKey">
<source>Public Key</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.publicKey" resname="settings.description.evoweb.recaptcha.publicKey">
<source>Public key of your reCAPTCHA-account. Get your keys at https://www.google.com/recaptcha/admin</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.privateKey" resname="settings.evoweb.recaptcha.privateKey">
<source>Private Key</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.privateKey" resname="settings.description.evoweb.recaptcha.privateKey">
<source>Private key of your reCAPTCHA-account</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.invisiblePublicKey" resname="settings.evoweb.recaptcha.invisiblePublicKey">
<source>Public key for invisible recaptcha</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.invisiblePrivateKey" resname="settings.evoweb.recaptcha.invisiblePrivateKey">
<source>Private key for invisible recaptcha</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.lang" resname="settings.evoweb.recaptcha.lang">
<source>Language</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.lang" resname="settings.description.evoweb.recaptcha.lang">
<source>Language of frontend (autodetected if empty). Valid language codes can be found at https://developers.google.com/recaptcha/docs/language?hl=de</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.enforceCaptcha" resname="settings.evoweb.recaptcha.enforceCaptcha">
<source>Enforcing captcha even in development mode</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.theme" resname="settings.evoweb.recaptcha.theme">
<source>Theme</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.theme" resname="settings.description.evoweb.recaptcha.theme">
<source>Theme of frontend can be light or dark</source>
</trans-unit>
<trans-unit id="settings.evoweb.recaptcha.robotMode" resname="settings.evoweb.recaptcha.robotMode">
<source>Robot Mode</source>
</trans-unit>
<trans-unit id="settings.description.evoweb.recaptcha.robotMode" resname="settings.description.evoweb.recaptcha.robotMode">
<source>If you use a frontend testing tool, which cannot solve the recaptcha</source>
</trans-unit>
<trans-unit id="settings.evoweb.sf-register.captchaId" resname="settings.evoweb.sf-register.captchaId">
<source>Frontend user registration what captcha to use</source>
</trans-unit>
</body>
</file>
</xliff>
64 changes: 36 additions & 28 deletions Configuration/Sets/Recaptcha/settings.definitions.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
categories:
recaptcha: ~
sf-register:
label: 'Frontend user registration'

settings:
evoweb.recaptcha.apiServer:
default: 'https://www.google.com/recaptcha/api.js'
label: 'reCAPTCHA API-server address'
type: string
description: 'api url'
evoweb.recaptcha.verifyServer:
default: 'https://www.google.com/recaptcha/api/siteverify'
label: 'reCAPTCHA VERIFY-server address'
type: string
description: 'verify url'
evoweb.recaptcha.publicKey:
default: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
label: 'reCAPTCHA public key: Public key of your reCAPTCHA-account'
type: string
category: recaptcha
evoweb.recaptcha.privateKey:
default: '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'
label: 'reCAPTCHA private key: Private key of your reCAPTCHA-account'
type: string
description: ''
category: recaptcha
evoweb.recaptcha.invisiblePublicKey:
default: ''
type: string
category: recaptcha
evoweb.recaptcha.invisiblePrivateKey:
default: ''
type: string
category: recaptcha
evoweb.recaptcha.apiServer:
default: 'https://www.google.com/recaptcha/api.js'
type: string
category: recaptcha
evoweb.recaptcha.verifyServer:
default: 'https://www.google.com/recaptcha/api/siteverify'
type: string
category: recaptcha
evoweb.recaptcha.lang:
default: '?hl='
label: 'reCAPTCHA language: Language of reCAPTCHA frontend (autodetected if empty)'
default: ''
type: string
description: ''
evoweb.recaptcha.enforceCaptcha:
default: 0
label: 'enforcing captcha even in development mode'
type: bool
description: ''
category: recaptcha
evoweb.recaptcha.theme:
default: 'light'
label: 'reCAPTCHA theme: Theme of reCAPTCHA frontend (light or dark)'
type: string
description: ''
enum:
light: 'light'
dark: 'dark'
category: recaptcha
evoweb.recaptcha.robotMode:
default: 0
label: 'reCAPTCHA robotMode: If you use a frontend testing tool, which cannot solve the recaptcha'
type: bool
description: ''
evoweb.sf_register.captchaId:
category: recaptcha
evoweb.recaptcha.enforceCaptcha:
default: 0
type: bool
category: recaptcha
evoweb.sf-register.captchaId:
default: 'recaptcha'
label: 'Frontend user registration what captcha to use'
type: string
description: ''
category: sf-register
12 changes: 9 additions & 3 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ plugin.tx_recaptcha {
# cat=plugin.recaptcha//04; type=string; label= reCAPTCHA private key: Private key of your reCAPTCHA-account
private_key = 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe

# cat=plugin.recaptcha//06; type=string; label= reCAPTCHA language: Language of reCAPTCHA frontend (autodetected if empty)
lang = ?hl=
# cat=plugin.recaptcha//05; type=string; label= reCAPTCHA public key: Public key of your reCAPTCHA-account
invisible_public_key =

# cat=plugin.recaptcha//07; type=boolean; label= enforcing captcha even in development mode
# cat=plugin.recaptcha//06; type=string; label= reCAPTCHA public key: Public key of your reCAPTCHA-account
invisible_private_key =

# cat=plugin.recaptcha//07; type=string; label= reCAPTCHA language: Language of reCAPTCHA frontend (autodetected if empty)
lang =

# cat=plugin.recaptcha//08; type=boolean; label= enforcing captcha even in development mode
enforceCaptcha = 0

# cat=plugin.recaptcha//10; type=string; label= reCAPTCHA theme: Theme of reCAPTCHA frontend (light or dark)
Expand Down
15 changes: 3 additions & 12 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ plugin.tx_recaptcha {
# look at https://www.google.com/recaptcha/admin to register a key for your server
private_key = {$plugin.tx_recaptcha.private_key ?? $evoweb.recaptcha.privateKey}

invisible_public_key = {$plugin.tx_recaptcha.invisible_public_key ?? $evoweb.recaptcha.invisiblePublicKey}
invisible_private_key = {$plugin.tx_recaptcha.invisible_private_key ?? $evoweb.recaptcha.invisiblePrivateKey}

api_server = {$plugin.tx_recaptcha.api_server ?? $evoweb.recaptcha.apiServer}
verify_server = {$plugin.tx_recaptcha.verify_server ?? $evoweb.recaptcha.verifyServer}

Expand All @@ -23,10 +26,6 @@ plugin.tx_recaptcha {

# register recaptcha as captcha for sf_register
plugin.tx_sfregister.settings {
recaptcha.public_key = {$plugin.tx_recaptcha.public_key ?? $evoweb.recaptcha.publicKey}

recaptcha.lang = {$plugin.tx_recaptcha.lang ?? $evoweb.recaptcha.lang}

# register recaptcha as captcha possibility
captcha.recaptcha = Evoweb\Recaptcha\Adapter\SfRegisterAdapter

Expand All @@ -52,11 +51,3 @@ plugin.tx_sfregister.view.partialRootPaths.1974 = EXT:recaptcha/Resources/Privat
# add settings for EXT:form
plugin.tx_form.settings.yamlConfigurations.1974 = EXT:recaptcha/Configuration/Yaml/FormSetup.yaml
plugin.tx_form.view.partialRootPaths.1974 = EXT:recaptcha/Resources/Private/Partials/


page.includeJSFooterlibs.recaptcha = {$plugin.tx_recaptcha.api_server ?? $evoweb.recaptcha.apiServer}{$plugin.tx_recaptcha.lang ?? $evoweb.recaptcha.lang}
page.includeJSFooterlibs.recaptcha {
external = 1
disableCompression = 1
excludeFromConcatenation = 1
}
17 changes: 17 additions & 0 deletions Documentation/BreakingChanges/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
Breaking Changes
================

12. October 2024
================

The possibility for configuring extra keys for invisible recaptcha was added. For
this to work, the partials needed to be modified. If you override the partials,
please check that they contain the changes.

In addition it was made possible to have more than one form with recaptcha on
a page. These needed a complete refactoring of form.js for the frontend. Check
that the inclusion via f:asset.script is the same in your site.

Lastly the inclusion of the recaptcha.js was change from TypoScript includeFooterJs
to f:asset.script. By this only on page with a form that is protected with
recaptcha, the js file gets loaded. For this to work, you need to synchronize
the partials if you override them.


13. August 2023
===============

Expand Down
4 changes: 2 additions & 2 deletions Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
interlink-shortcode="evoweb/recaptcha"
/>
<project title="recaptcha"
release="13.0.2"
version="13.0.2"
release="14.0.0"
version="14.0.0"
copyright="since 2015 by evoWeb"
/>
<inventory id="t3tsref" url="https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/"/>
Expand Down
37 changes: 21 additions & 16 deletions Resources/Private/Partials/Form/Captcha.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:r="http://typo3.org/ns/Evoweb/SfRegister/ViewHelpers"
xmlns:sf="http://typo3.org/ns/Evoweb/SfRegister/ViewHelpers"
xmlns:r="http://typo3.org/ns/Evoweb/Recaptcha/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:asset.script identifier="recaptcha_form" src="EXT:recaptcha/Resources/Public/JavaScript/Frontend/form.js"/>
<f:variable name="hasCapchaError"><f:form.validationResults
for="user.{fieldName}">{validationResults.flattenedErrors -> f:count()}</f:form.validationResults></f:variable>
<f:if condition="!{settings.hasOriginalRequest}||{hasCapchaError}">
<div class="col-md-6 mb-3 {fieldName} {options.cssClass}">
<f:form.hidden
property="{fieldName}"
id="{fieldName}"
value=""
data="{recaptcha-form-field: ''}"
respectSubmittedDataValue="false"
/>
<div><r:form.captcha type="recaptcha" /></div>
</div>
</f:if>

<r:form.recaptcha>
<f:asset.script identifier="recaptcha_form" src="EXT:recaptcha/Resources/Public/JavaScript/Frontend/form.js"/>
<f:asset.script identifier="recaptcha" async="true" src="{configuration.api_server}{f:if(condition: configuration.lang, then: '?hl={configuration.lang}')}"/>
<f:variable name="hasCapchaError"><f:form.validationResults
for="user.{fieldName}">{validationResults.flattenedErrors -> f:count()}</f:form.validationResults></f:variable>
<f:if condition="!{settings.hasOriginalRequest}||{hasCapchaError}">
<div class="col-md-6 mb-3 {fieldName} {options.cssClass}">
<f:form.hidden
property="{fieldName}"
id="{fieldName}"
value=""
data="{recaptcha-form-field: ''}"
respectSubmittedDataValue="false"
/>
<div><sf:form.captcha type="recaptcha" /></div>
</div>
</f:if>
</r:form.recaptcha>
</html>
9 changes: 7 additions & 2 deletions Resources/Private/Partials/Form/Navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@
</f:form.button>
</span>
</f:then>

<f:else>
<span class="btn-group next submit">
<f:if condition="{form.formDefinition.renderingOptions.useInvisibleRecaptcha}">
<f:then>
<r:form.recaptcha>
<f:if condition="{showCaptcha}">
<f:then>
<f:variable name="publicKey"><f:if condition="{configuration.invisible_public_key}">
<f:then>{configuration.invisible_public_key}</f:then>
<f:else>{configuration.public_key}</f:else>
</f:if></f:variable>
<input type="hidden" name="recaptcha-invisible" value="1"/>
<f:form.button
id="{form.formDefinition.identifier}-submit"
class="btn btn-primary g-recaptcha"
data="{
callback: 'onRecaptchaSubmit',
sitekey: configuration.public_key
sitekey: publicKey,
invisible-recaptcha-form-submit: ''
}"
>
<formvh:translateElementProperty element="{form}" renderingOptionProperty="submitButtonLabel"/>
Expand Down
6 changes: 5 additions & 1 deletion Resources/Private/Partials/Recaptcha.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers"
xmlns:r="http://typo3.org/ns/Evoweb/Recaptcha/ViewHelpers"
data-namespace-typo3-fluid="true">

<formvh:renderRenderable renderable="{element}">
<r:form.recaptcha>
<f:asset.script identifier="recaptcha_form" src="EXT:recaptcha/Resources/Public/JavaScript/Frontend/form.js"/>
<f:if condition="{element.parentRenderable.parentRenderable.renderingOptions.useInvisibleRecaptcha}">
<f:then>
<f:if condition="{showCaptcha}">
<f:asset.script identifier="recaptcha_form" src="EXT:recaptcha/Resources/Public/JavaScript/Frontend/form.js"/>
<f:asset.script identifier="recaptcha" async="true" src="{configuration.api_server}{f:if(condition: configuration.lang, then: '?hl={configuration.lang}')}"/>
<f:form.hidden
property="{element.identifier}"
id="{element.uniqueIdentifier}"
Expand All @@ -22,6 +24,8 @@
<f:render partial="Field/Field" arguments="{element: element, doNotShowLabel: element.renderingOptions.doNotShowLabel}" contentAs="elementContent">
<f:if condition="{showCaptcha}">
<f:then>
<f:asset.script identifier="recaptcha" defer="true" src="{configuration.api_server}{f:if(condition: configuration.lang, then: '?hl={configuration.lang}')}"/>
<f:asset.script identifier="recaptcha_form" src="EXT:recaptcha/Resources/Public/JavaScript/Frontend/form.js"/>
<f:form.hidden
property="{element.identifier}"
id="{element.uniqueIdentifier}"
Expand Down
Loading

0 comments on commit 9e7c6dc

Please sign in to comment.