<?php
namespace App\Controller;
use App\Controller\DefaultValuesController;
use App\Document\DataFeed;
use App\Document\Product;
use App\Document\SchedulerJob;
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\ODM\MongoDB\Aggregation\Aggregation;
use Doctrine\ODM\MongoDB\DocumentManager;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* @Route("/")
*/
class AuthenticationController extends AbstractController
{
public static function getName()
{
return "Authentication";
}
public static function getAdminName()
{
return "guard";
}
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(
LoggerInterface $logger
)
{
$this->logger = $logger;
$this->logger->debug($this->logPrefix(__METHOD__).' ');
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
$this->logger->debug($this->logPrefix(__METHOD__).' ');
if ($this->getUser()) {
//return $this->redirectToRoute('admin_default');
return $this->render('master/guard/auth-login.html.twig');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('master/guard/auth-login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(ManagerRegistry $managerRegistry)
{
$this->logger->debug($this->logPrefix(__METHOD__).' ');
return $this->redirectToRoute('app_login');
/** @var DocumentManager $dm */
$dm = $managerRegistry->getManager("master");
//throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
private function logPrefix($message)
{
$limit = 70;
$content = explode("::",$message);
$len = $limit - strlen($content[0]);
return $content[0].str_pad(' '.$content[1],$len,'.',STR_PAD_LEFT).' ';
}
}