<?php
namespace App\Controller;
use App\Form\MailerFormType;
use App\Service\CaptchaService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
public function __construct(
private CaptchaService $captchaService,
)
{}
#[Route('/', name: 'home_page')]
public function page(): Response
{
$form = $this->createForm(MailerFormType::class);
return $this->render('home/index.html.twig', [
'mailerForm' => $form->createView()
]);
}
#[Route('/captcha/image', name: 'captcha_image')]
public function image()
{
define('USE_SESSION', true);
$code = $this->captchaService->codeGenerator();
$rootPath = $this->getParameter('kernel.project_dir');
$imagePath = $rootPath . '/public/assets/doapp/captcha/bg.png';
$fontPath = $rootPath . '/public/assets/doapp/captcha/oswald.ttf';
$this->captchaService->backgroundGenerator($imagePath, $fontPath, $code);
}
#[Route('/captcha/handler', name: 'captcha_handler')]
public function handler(): Response
{
$result = $this->captchaService->captchaHandler();
return new Response(json_encode($result));
}
}