src/Controller/GuardController.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\DefaultValuesController;
  4. //use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
  5. use Doctrine\ODM\MongoDB\Aggregation\Aggregation;
  6. //use Doctrine\ODM\MongoDB\DocumentManager;
  7. use Doctrine\ORM\EntityManager;
  8. use Psr\Log\LoggerInterface;
  9. use Symfony\Bridge\Doctrine\ManagerRegistry;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. /**
  16.  * @Route("/")
  17.  */
  18. class GuardController extends AbstractController
  19. {
  20.     public static function getName()
  21.     {
  22.         return "Authentication";
  23.     }
  24.     public static function getAdminName()
  25.     {
  26.         return "guard";
  27.     }
  28.     /**
  29.      * @var LoggerInterface
  30.      */
  31.     private $logger;
  32.     public function __construct(
  33.         LoggerInterface $logger
  34.     )
  35.     {
  36.         $this->logger $logger;
  37.         $this->logger->debug($this->logPrefix(__METHOD__).' ');
  38.     }
  39.     /**
  40.      * @Route("/login", name="app_login")
  41.      */
  42.     public function login(AuthenticationUtils $authenticationUtils): Response
  43.     {
  44.         $this->logger->debug($this->logPrefix(__METHOD__).' ');
  45.         if ($this->getUser()) {
  46.             //return $this->redirectToRoute('admin_default');
  47.             return $this->render('master/guard/auth-login.html.twig');
  48.         }
  49.         // get the login error if there is one
  50.         $error $authenticationUtils->getLastAuthenticationError();
  51.         // last username entered by the user
  52.         $lastUsername $authenticationUtils->getLastUsername();
  53.         return $this->render('master/guard/auth-login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  54.     }
  55.     /**
  56.      * @Route("/logout", name="app_logout")
  57.      */
  58.     public function logout(ManagerRegistry $managerRegistry)
  59.     {
  60.         $this->logger->debug($this->logPrefix(__METHOD__).' ');
  61.         return $this->redirectToRoute('app_login');
  62.         /** @var EntityManager $em */
  63.         $em =  $managerRegistry->getManager("master");
  64.         //throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  65.     }
  66.     private function logPrefix($message)
  67.     {
  68.         $limit 70;
  69.         $content explode("::",$message);
  70.         $len $limit strlen($content[0]);
  71.         return $content[0].str_pad(' '.$content[1],$len,'.',STR_PAD_LEFT).' ';
  72.     }
  73. }