0

I added a captcha bot to my registration form.

My captcha bot works perfectly fine on local (on dev and prod mode) but when I deployed the code to Heroku the /register page doesn't work anymore. I get this error :

ERROR: BotDetect requires the GD library and its support library: libpng, libjpeg and FreeType 2. You can read more about installing/enabling them at http://php.net/manual/en/book.image.php.

You can see the error here : website link

I dont think the problem is from my code, but here is it: Controlleur code :

/**
 * @Route("/register", name="user_register", methods={"GET","POST"})
 */
public function register(Request $request,UserPasswordEncoderInterface $encoder): Response
{
    $user = new User();
    $form = $this->createForm(RegisterType::class, $user, ['validation_groups' => ['register'], ]);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {

        $hash = $encoder->encodePassword($user,$user->getPassword());
        $user->setPassword($hash);

        $this->addFlash('success', 'You succesfully registered, Now Login!');

        $entityManager = $this->getDoctrine()->getManager();
        $entityManager->persist($user);
        $entityManager->flush();
        

        return $this->redirectToRoute('user_login');
}
    return $this->render('authentication/register.html.twig', [
        'user' => $user,
        'form' => $form->createView(),
    ]);
}

My form :

class RegisterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username')
            ->add('password',PasswordType::class)
            ->add('password2',PasswordType::class)
            ->add('email')
            ->add('name')
            ->add('captchaCode', CaptchaType::class, [
                'captchaConfig' => 'ExampleCaptchaUserRegistration',
                'constraints' => [
                    new ValidCaptcha([
                        'message' => 'Invalid captcha, please try again',
                    ]),
                ],]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => User::class,
        ]);
    }
}

The captchaCode on User.php

/**
 * @CaptchaAssert\ValidCaptcha(
 *     message = "Invalid captcha, please try again",
 *     groups={"register"}
 * )
 */

protected $captchaCode;

public function getCaptchaCode()
{
  return $this->captchaCode;
}

public function setCaptchaCode($captchaCode)
{
  $this->captchaCode = $captchaCode;
}

Heroku logs error :

2020-09-17T10:30:04.377111+00:00 heroku[router]: at=info method=GET path="/register" host=bazar-chic.herokuapp.com request_id=30e115f0-023b-4f59-a0b6-34777e9086ca fwd="94.23.206.14" dyno=web.1 connect=1ms service=15ms status=500 bytes=1288 protocol=https 2020-09-17T10:30:04.375520+00:00 app[web.1]: 10.63.54.150 - - [17/Sep/2020:10:30:04 +0000] "GET /register HTTP/1.1" 500 918 "https://bazar-chic.herokuapp.com/register" "WordPress/5.5.1; https://symfonyquestions.com 2020-09-17T10:30:04.806894+00:00 heroku[router]: at=info method=HEAD path="/register" host=bazar-chic.herokuapp.com request_id=2d342c4d-5356-47aa-9517-017a83dd5cbc fwd="94.23.206.14" dyno=web.1 connect=0ms service=16ms status=500 bytes=330 protocol=https 2020-09-17T10:30:04.807744+00:00 app[web.1]: 10.102.182.112 - - [17/Sep/2020:10:30:04 +0000] "HEAD /register HTTP/1.1" 500 - "https://bazar-chic.herokuapp.com/register" "WordPress/5.5.1; https://symfonyquestions.com

Meh Di
  • 93
  • 1
  • 10
  • 1
    According to the error, the `gd` extension is not available. As you can see in the [heroku support](https://devcenter.heroku.com/articles/php-support#using-optional-extensions) you can enable it by adding `"ext-gd": "*",` to the `require` section of `composer.json`. – msg Sep 17 '20 at 09:57
  • @msg I did that, but now I am getting 500 code error page. The problem I cant run the project on dev mode inside Heroku to find the error :( – Meh Di Sep 17 '20 at 10:14
  • 1
    Then you now have to go and check what the error _log_ has to say, to find out what the reasons was. – CBroe Sep 17 '20 at 10:17
  • @CBroe It says Build succeeded and I don't see any error on Heroku logs .. – Meh Di Sep 17 '20 at 10:19
  • Did you check in the correct place(s)? https://stackoverflow.com/a/46021507/1427878 – CBroe Sep 17 '20 at 10:22
  • @CBroe Oh! Now I run `heroku logs -t` and I saw 500 error on the cmd. I edited my question and I added the logs error. – Meh Di Sep 17 '20 at 10:30

1 Answers1

0

try with ngrok in localhost . https://ngrok.com/