excelwebzone / EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field for Symfony.
MIT License
395 stars 160 forks source link

Can't specify action name on v3 #259

Closed phoenix741 closed 3 years ago

phoenix741 commented 3 years ago

If i use V3 reCaptcha and set an action_name:

        ->add(
            'recaptcha',
            EWZRecaptchaV3Type::class,
            array(
                'mapped' => false,
                'action_name' => 'contact',
                'constraints' => array(
                    new IsTrueV3()
                )
            )
        );

When i validate the formulaire i have an error that say i should check "I'm not a robot" (the case is not present in v3)

The reason is in the file Validator\Constraints\IsTrueValidatorV3.php. The method isTokenValid check only if action is form :

 /**
   * @param string $token
   *
   * @return bool
   */
  private function isTokenValid($token)
  {
      try {
          $remoteIp = $this->requestStack->getCurrentRequest()->getClientIp();

          $recaptcha = new ReCaptcha($this->secretKey);

          $response = $recaptcha
              ->setExpectedAction('form')
              ->setScoreThreshold($this->scoreThreshold)
              ->verify($token, $remoteIp);

Thanks.

Sven-Ve commented 3 years ago

Same problem here.

Sven-Ve commented 3 years ago

I created pull request #263