src/Controller/Common/SecurityController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Common;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  10. /**
  11.  * Class SecurityController
  12.  * @package App\Controller\Common
  13.  */
  14. class SecurityController extends AbstractController
  15. {
  16.     use TargetPathTrait;
  17.     /**
  18.      * @Route("/login", name="login")
  19.      * @param Request $request
  20.      * @return RedirectResponse|Response
  21.      */
  22.     public function login(Request $request)
  23.     {
  24.         if ($this->getUser()) {
  25.             return $this->redirectToRoute('app.homepage');
  26.         }
  27.         $target $this->generateUrl($request->attributes->get('_route'));
  28.         $this->saveTargetPath($request->getSession(), 'test'$target);
  29.         $this->saveTargetPath($request->getSession(), 'basic'$target);
  30.         $this->saveTargetPath($request->getSession(), 'cas'$target);
  31.         return $this->render('common/security/login.html.twig');
  32.     }
  33.     /**
  34.      * @Route("/login/basic", name="login.basic")
  35.      * @param AuthenticationUtils $authenticationUtils
  36.      * @return Response
  37.      */
  38.     public function loginBasic(AuthenticationUtils $authenticationUtils): Response
  39.     {
  40.         if ($this->getUser()) {
  41.             return $this->redirectToRoute('app.login');
  42.         }
  43.         // get the login error if there is one
  44.         $error $authenticationUtils->getLastAuthenticationError();
  45.         // last username entered by the user
  46.         $lastUsername $authenticationUtils->getLastUsername();
  47.         return $this->render('common/security/login_basic.html.twig', [
  48.             'last_username' => $lastUsername'error' => $error
  49.         ]);
  50.     }
  51.     /**
  52.      * @Route(path="/login/cas", name="login.cas")
  53.      * @return RedirectResponse
  54.      */
  55.     public function loginCas()
  56.     {
  57.         return $this->redirectToRoute('app.login');
  58.     }
  59.     /**
  60.      * @Route("/logout", name="logout")
  61.      */
  62.     public function logout()
  63.     {
  64.     }
  65. }