<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\ORM\EntityManagerInterface;
use UltraMsg\WhatsAppApi;
class PublicController extends AbstractController
{
private $translator;
private $em;
public function __construct(TranslatorInterface $translator, EntityManagerInterface $em)
{
$this->translator = $translator;
$this->em = $em;
}
/**
* @Route("/", name="public_home")
*/
public function public_home()
{
if ($this->getUser()) {
if ($this->getUser()->hasRole('ROLE_ADMIN')) {
return $this->redirectToRoute('admin');
}
}
return $this->redirectToRoute('public_login');
}
/**
* @Route("/login", name="public_login")
*/
public function public_login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('public_home');
}
$error = $authenticationUtils->getLastAuthenticationError();
if ($error) {
$errorMsg = null;
if ($error instanceof \Symfony\Component\Security\Core\Exception\BadCredentialsException) {
$errorMsg = $this->translator->trans('messages.errors.login.badCredentials');
} else {
$errorMsg = $error->getMessageKey();
}
$this->addFlash('danger', $errorMsg);
}
return $this->render('public/login.html.twig', [
'last_username' => $authenticationUtils->getLastUsername()
]);
}
/**
* @Route("/logout", name="public_logout")
*/
public function public_logout()
{
}
}