<?php
namespace App\Controller\Common;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Http\Util\TargetPathTrait;
/**
* Class SecurityController
* @package App\Controller\Common
*/
class SecurityController extends AbstractController
{
use TargetPathTrait;
/**
* @Route("/login", name="login")
* @param Request $request
* @return RedirectResponse|Response
*/
public function login(Request $request)
{
if ($this->getUser()) {
return $this->redirectToRoute('app.homepage');
}
$target = $this->generateUrl($request->attributes->get('_route'));
$this->saveTargetPath($request->getSession(), 'test', $target);
$this->saveTargetPath($request->getSession(), 'basic', $target);
$this->saveTargetPath($request->getSession(), 'cas', $target);
return $this->render('common/security/login.html.twig');
}
/**
* @Route("/login/basic", name="login.basic")
* @param AuthenticationUtils $authenticationUtils
* @return Response
*/
public function loginBasic(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app.login');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('common/security/login_basic.html.twig', [
'last_username' => $lastUsername, 'error' => $error
]);
}
/**
* @Route(path="/login/cas", name="login.cas")
* @return RedirectResponse
*/
public function loginCas()
{
return $this->redirectToRoute('app.login');
}
/**
* @Route("/logout", name="logout")
*/
public function logout()
{
}
}