src/Controller/FrontendBundle/SecurityController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontendBundle;
  3. use Psr\Log\LoggerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. use App\BackendBundle\Helper\SiteTitleHelper;
  11. use App\BackendBundle\Helper\ValidationHelper;
  12. class SecurityController extends AbstractController {
  13.     private $siteTitleHelper;
  14.     private $validationHelper;
  15.     private $authenticationUtils;
  16.     private $tokenStorage;
  17.     public function __construct(SiteTitleHelper $sitetitlehelperValidationHelper $validationhelperAuthenticationUtils $authutils,
  18.             TokenStorageInterface $tokenstorage) {
  19.         $this->siteTitleHelper $sitetitlehelper;
  20.         $this->validationHelper $validationhelper;
  21.         $this->authenticationUtils $authutils;
  22.         $this->tokenStorage $tokenstorage;
  23.     }
  24.     /**
  25.      * @return \Symfony\Component\HttpFoundation\Response
  26.      * @Route("/login", name="security_login", defaults={"title": "Login", "description": "Loggen Sie sich auf berufsreise.at ein und entdecken Sie die Tiroler Berufsorientierungswelt!"}) 
  27.      */
  28.     public function loginAction(Request $request) {
  29.         $this->siteTitleHelper->setTitleDescription($request);
  30.         /* @var $authenticationUtils AuthenticationUtils */
  31.         //$authenticationUtils = $this->get('security.authentication_utils');
  32.         // get the login error if there is one
  33.         $error $this->authenticationUtils->getLastAuthenticationError();
  34.         $user $this->getUser();
  35.         if (!empty($user)) {
  36.             return $this->redirectToRoute('frontpage_public');
  37.         }
  38.         // last username entered by the user
  39.         $lastUsername $this->authenticationUtils->getLastUsername();
  40.         $validationData $this->validationHelper->getFormValidationData('login');
  41.         return $this->render('@frontend/login/login.html.twig', array(
  42.                     'validationData' => $validationData,
  43.                     'last_username' => $lastUsername,
  44.                     'error' => $error,
  45.         ));
  46.     }
  47.     /**
  48.      * @return \Symfony\Component\HttpFoundation\Response
  49.      * @Route("/login_redirect", name="security_login_redirect") 
  50.      */
  51.     public function loginRedirectAction(Request $requestLoggerInterface $logger) {
  52.         $logger->info("Handle login redirect action...");
  53.         $securityChecker $this->get('security.authorization_checker');
  54.         if ($securityChecker->isGranted('ROLE_COMPANY')) {
  55.             return $this->redirectToRoute('company_default_private');
  56.         }
  57.         if ($securityChecker->isGranted('ROLE_SECONDARY_SCHOOL')) {
  58.             return $this->redirectToRoute('school_default_private');
  59.         }
  60.         if ($securityChecker->isGranted('ROLE_BOPARTNER')) {
  61.             return $this->redirectToRoute('bopartner_default_private');
  62.         }
  63.         if ($securityChecker->isGranted('ROLE_TEACHER')) {
  64.             return $this->redirectToRoute('teacher_default_private');
  65.         }
  66.         if ($securityChecker->isGranted('ROLE_DIRECTOR')) {
  67.             return $this->redirectToRoute('director_default_private');
  68.         }
  69.         if ($securityChecker->isGranted('ROLE_SCHOOL_CLASS')) {
  70.             return $this->redirectToRoute('school_class_default_private');
  71.         }
  72.         return $this->redirectToRoute('frontpage_public');
  73.     }
  74.     /**
  75.      * @return \Symfony\Component\HttpFoundation\Response
  76.      * @Route("/logout", name="security_logout") 
  77.      */
  78.     public function logoutAction(Request $request) {
  79.         //$this->get('security.token_storage')->setToken(null);
  80.         $this->tokenStorage->setToken(null);
  81.         $request->getSession()->invalidate();
  82.         return $this->redirect($this->generateUrl('frontpage_public'));
  83.     }
  84.     /**
  85.      * @return \Symfony\Component\HttpFoundation\Response
  86.      * @Route("/login_check", name="security_check") 
  87.      */
  88.     public function checkAction(Request $requestLoggerInterface $logger) {
  89.         $logger->info('Login check action');
  90.     }
  91. }