<?php
namespace App\Controller;
use App\Utils\DefaultService;
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\CurlPost;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends AbstractController
{
private $defaultService;
public function __construct(DefaultService $defaultService)
{
$this->defaultService = $defaultService;
}
public function index()
{
//Metaetiquetas para la pagina principal
$url = 'homefrontend';
//seo on page
$seo_on_page = $this->defaultService->DevolverSeoOnPage($url);
// highlighted
$highlighted = $this->defaultService->DevolverHighlighted();
// about
$about = $this->defaultService->DevolverAbout();
// board
$board = $this->defaultService->ListarBoard();
// banners
$banners = $this->defaultService->ListarBanners();
// faqs
$faqs = $this->defaultService->ListarFaqs();
return $this->render('frontend/default/index.html.twig', array(
'seo_on_page' => $seo_on_page,
'highlighted' => $highlighted,
'about' => $about,
'board' => $board,
'banners' => $banners,
'faqs' => $faqs
));
}
public function error404()
{
//Metaetiquetas para la pagina principal
$url = 'error404';
$seo_on_page = $this->defaultService->DevolverSeoOnPage($url);
$response = new Response("", 400);
return $this->render('frontend/error404.html.twig', array(
'seo_on_page' => $seo_on_page
), $response
);
}
public function contacto(Request $request)
{
//Metaetiquetas para la pagina principal
$url = 'contacto';
$seo_on_page = $this->defaultService->DevolverSeoOnPage($url);
$datos_contacto = $this->defaultService->ListarFooterDatos();
//Recaptcha
$recaptcha_publick_key = $this->getParameter('recaptcha_publick_key');
if ($request->getMethod() == "POST") {
$nombre = $request->get('nombre');
$email = $request->get('email');
$mensaje = $request->get('mensaje');
$recaptcha_response = $request->get('g-recaptcha-response');
$secret = $this->getParameter('recaptcha_private_key');
$recaptcha = new ReCaptcha($secret, new CurlPost());
$result_recaptcha = $recaptcha->verify($recaptcha_response, $_SERVER['REMOTE_ADDR']);
if ($result_recaptcha->isSuccess()) {
$this->defaultService->ProcesarContacto($nombre, $email, $mensaje);
return $this->redirectToRoute('contactoenviado');
} else {
$error = "";
foreach ($result_recaptcha->getErrorCodes() as $code) {
$error = $code . ', ';
}
return $this->render('frontend/default/contacto.html.twig', array(
'seo_on_page' => $seo_on_page,
'datos_contacto' => $datos_contacto,
'recaptcha_publick_key' => $recaptcha_publick_key,
'message' => $error
)
);
}
}
return $this->render('frontend/default/contacto.html.twig', array(
'seo_on_page' => $seo_on_page,
'datos_contacto' => $datos_contacto,
'recaptcha_publick_key' => $recaptcha_publick_key
)
);
}
public function contactoenviado(Request $request)
{
//Metaetiquetas para la pagina principal
$url = 'contactoenviado';
$seo_on_page = $this->defaultService->DevolverSeoOnPage($url);
$datos_contacto = $this->defaultService->ListarFooterDatos();
return $this->render('frontend/default/contactoenviado.html.twig', array(
'seo_on_page' => $seo_on_page,
'datos_contacto' => $datos_contacto,
)
);
}
/**
* para renderizar el footer
* @return Response
*/
public function mostrarFooter()
{
//Categorias
$footer_datos = $this->defaultService->ListarFooterDatos();
return $this->render('frontend/block/footer.html.twig', array(
'footer_datos' => $footer_datos,
)
);
}
}