src/Controller/AuthenticationController.php line 60

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