99use Dot \FlashMessenger \FlashMessenger ;
1010use Dot \Mail \Exception \MailException ;
1111use Fig \Http \Message \RequestMethodInterface ;
12+ use Frontend \App \Service \RecaptchaService ;
1213use Frontend \Contact \Form \ContactForm ;
1314use Frontend \Contact \Service \MessageService ;
1415use Frontend \Plugin \FormsPlugin ;
@@ -31,6 +32,9 @@ class ContactController extends AbstractActionController
3132 /** @var MessageService $messageService */
3233 protected MessageService $ messageService ;
3334
35+ /** @var RecaptchaService $recaptchaService */
36+ protected RecaptchaService $ recaptchaService ;
37+
3438 /** @var AuthenticationServiceInterface $authenticationService */
3539 protected AuthenticationServiceInterface $ authenticationService ;
3640
@@ -46,13 +50,16 @@ class ContactController extends AbstractActionController
4650 /**
4751 * UserController constructor.
4852 * @param MessageService $messageService
53+ * @param RecaptchaService $recaptchaService
4954 * @param RouterInterface $router
5055 * @param TemplateRendererInterface $template
5156 * @param AuthenticationService $authenticationService
5257 * @param FlashMessenger $messenger
5358 * @param FormsPlugin $forms
59+ * @param array $config
5460 * @Inject({
5561 * MessageService::class,
62+ * RecaptchaService::class,
5663 * RouterInterface::class,
5764 * TemplateRendererInterface::class,
5865 * AuthenticationService::class,
@@ -63,6 +70,7 @@ class ContactController extends AbstractActionController
6370 */
6471 public function __construct (
6572 MessageService $ messageService ,
73+ RecaptchaService $ recaptchaService ,
6674 RouterInterface $ router ,
6775 TemplateRendererInterface $ template ,
6876 AuthenticationService $ authenticationService ,
@@ -71,6 +79,7 @@ public function __construct(
7179 array $ config = []
7280 ) {
7381 $ this ->messageService = $ messageService ;
82+ $ this ->recaptchaService = $ recaptchaService ;
7483 $ this ->router = $ router ;
7584 $ this ->template = $ template ;
7685 $ this ->authenticationService = $ authenticationService ;
@@ -94,9 +103,9 @@ public function formAction(): ResponseInterface
94103 $ data = $ request ->getParsedBody ();
95104 //check recaptcha
96105 if (isset ($ data ['g-recaptcha-response ' ])) {
97- if (!$ this ->messageService -> recaptchaIsValid ($ data ['g-recaptcha-response ' ])) {
106+ if (! $ this ->recaptchaService -> setResponse ($ data ['g-recaptcha-response ' ])-> isValid ( )) {
98107 unset($ data ['g-recaptcha-response ' ]);
99- $ this ->messenger ->addError ('Wrong recaptcha ' );
108+ $ this ->messenger ->addError ('Captcha verification failed. Please try again. ' );
100109 return new RedirectResponse ($ request ->getUri (), 303 );
101110 }
102111 } else {
0 commit comments