我在注册表格中添加了一个验证码机器人。
我的验证码机器人在本地(在dev
和prod
模式下可以正常工作)
但是当我将代码部署到Heroku时,/ register页面不再起作用。
我收到此错误:
错误:BotDetect需要GD库及其支持库: libpng,libjpeg和FreeType2。您可以阅读更多有关 在http://php.net/manual/en/book.image.php上安装/启用它们。
您可以在这里看到错误:website link
我不认为问题出在我的代码上,但这是它: 控制代码:
/**
* @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(),
]);
}
我的表格:
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,
]);
}
}
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记录错误:
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服务= 15ms状态= 500字节= 1288 协议= https 2020-09-17T10:30:04.375520 + 00:00 app [web.1]: 10.63.54.150--[17 / Sep / 2020:10:30:04 +0000]“获取/注册HTTP / 1.1” 500918“ 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服务= 16ms status = 500字节= 330 协议= 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