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