Skip to content

Commit

Permalink
Add field validation for recaptcha action names
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Mühl committed May 24, 2019
1 parent 310e861 commit 7eb5e86
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Resources/contao/classes/RecaptchaHooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Contao;

class RecaptchaHooks
{
public function addRecaptchaActionRegexp($regexpName, $value, Widget $widget)
{
if ($regexpName !== 'recaptcha') return false;

if (preg_match('/[^a-zA-Z\/_]/', $value) !== 0) {
$widget->addError($GLOBALS['TL_LANG']['ERR']['recaptcha_rgxp']);
}

return true;
}
}
1 change: 1 addition & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use DieSchittigs\RecaptchaBundle\Form\FormRecaptcha;

$GLOBALS['TL_FFL']['captcha'] = FormRecaptcha::class;
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = [Contao\RecaptchaHooks::class, 'addRecaptchaActionRegexp'];

array_insert($GLOBALS['TL_CTE']['miscellaneous'], 0, [
'backgroundrecaptcha' => Contao\ContentBackgroundRecaptcha::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_content']['recaptcha_action'],
'exclude' => true,
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'required' => true],
'eval' => ['tl_class' => 'w50', 'required' => true, 'rgxp' => 'recaptcha'],
'sql' => 'VARCHAR(120) NOT NULL',
],
];
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'],
'inputType' => 'text',
'sql' => "varchar(120) unsigned NOT NULL default ''",
'eval' => ['tl_class' => 'w50']
'eval' => ['tl_class' => 'w50', 'rgxp' => 'recaptcha']
],
];

Expand Down
1 change: 1 addition & 0 deletions src/Resources/contao/languages/de/default.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$GLOBALS['TL_LANG']['ERR']['recaptcha'] = "reCAPTCHA konnte nicht bestätigen, dass Sie kein Roboter sind. Bitte versuchen Sie es noch einmal.";
$GLOBALS['TL_LANG']['ERR']['recaptcha_rgxp'] = "reCAPTCHA Aktionen können nur die Buchstaben a-z (klein- und großgeschrieben), sowie die Zeichen _ und / enthalten.";

$GLOBALS['TL_LANG']['CTE']['miscellaneous'] = "Verschiedenes";
$GLOBALS['TL_LANG']['CTE']['backgroundrecaptcha'][0] = "Hintergrund reCAPTCHA v3";
1 change: 1 addition & 0 deletions src/Resources/contao/languages/en/default.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$GLOBALS['TL_LANG']['ERR']['recaptcha'] = "reCAPTCHA could not verify that you're not a robot. Please try again.";
$GLOBALS['TL_LANG']['ERR']['recaptcha_rgxp'] = "reCAPTCHA actions can only include the letters a-z (lower and upper case) and the symbols _ and /.";

$GLOBALS['TL_LANG']['CTE']['miscellaneous'] = "Miscellaneous";
$GLOBALS['TL_LANG']['CTE']['backgroundrecaptcha'][0] = "Background reCAPTCHA v3";

0 comments on commit 7eb5e86

Please sign in to comment.