lib/composer/SecurityBundle/src/VisualMedia/SecurityBundle/Controller/SecurityController.php line 134

Open in your IDE?
  1. <?php
  2. /**
  3. * Security Controller
  4. *
  5. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6. * @author Gideon Oudhuis <g.oudhuis@visualmedia.nl>
  7. */
  8. namespace VisualMedia\SecurityBundle\Controller;
  9. use Symfony\Bridge\Twig\TokenParser\DumpTokenParser;
  10. use Symfony\Component\Cache\Adapter\AdapterInterface;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  14. use Symfony\Component\Security\Core\Security;
  15. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  16. use VisualMedia\LisaBundle\Controller\BaseController;
  17. use VisualMedia\SecurityBundle\Form\Type\FrontendLoginType;
  18. use VisualMedia\SecurityBundle\Form\Type\ManageLoginType;
  19. use VisualMedia\SecurityBundle\Security\BaseLoginFormAuthenticator;
  20. use VisualMedia\SecurityBundle\Service\LoginHandler;
  21. /**
  22. * Security Controller
  23. */
  24. class SecurityController extends BaseController
  25. {
  26. /**
  27. * @param Request $request
  28. * @return Response
  29. */
  30. public function backendLoginAction(Request $request): Response
  31. {
  32. $authenticationUtils = $this->get(AuthenticationUtils::class);
  33. $lastUsername = $authenticationUtils->getLastUsername();
  34. // Get the login error if there is one.
  35. // $error = $authenticationUtils->getLastAuthenticationError();
  36. // $form = $this->createForm(ManageLoginType::class, array(
  37. // '_username' => $lastUsername,
  38. // ));
  39. // $form->handleRequest($request);
  40. return $this->render('@VisualMediaSecurity/Security/login.html.twig', array(
  41. 'last_username' => $lastUsername,
  42. 'block' => false,
  43. // 'form' => $form->createView(),
  44. // 'error' => $error,
  45. ));
  46. }
  47. /**
  48. * @param Request $request
  49. * @return Response
  50. */
  51. public function ssiBackendLoginFormAction(Request $request, $template = '@VisualMediaSecurity/Security/login_form.html.twig', $redirect_url = null): Response
  52. {
  53. $masterRequest = $this->get('request_stack')->getMasterRequest();
  54. $authenticationUtils = $this->get(AuthenticationUtils::class);
  55. $lastUsername = $authenticationUtils->getLastUsername();
  56. $error = $authenticationUtils->getLastAuthenticationError();
  57. $request->attributes->set('template', $template);
  58. $request->attributes->set('redirect_url', $redirect_url);
  59. $form = $this->createForm(ManageLoginType::class, array(
  60. '_username' => $lastUsername,
  61. LoginHandler::RETURN_URL => $redirect_url,
  62. ));
  63. $form->handleRequest($masterRequest);
  64. return $this->render($template, array(
  65. 'error' => $error,
  66. 'form' => $form->createView(),
  67. 'last_username' => $lastUsername,
  68. 'block' => false,
  69. ));
  70. }
  71. /**
  72. * @param Request $request
  73. * @return Response
  74. */
  75. public function frontendLoginAction(Request $request): Response
  76. {
  77. $authenticationUtils = $this->get(AuthenticationUtils::class);
  78. $lastUsername = $authenticationUtils->getLastUsername();
  79. // Get the login error if there is one.
  80. // $error = $authenticationUtils->getLastAuthenticationError();
  81. // $form = $this->createForm(FrontendLoginType::class, array(
  82. // '_username' => $lastUsername,
  83. // ));
  84. // $form->handleRequest($request);
  85. return $this->render('@VisualMediaSecurity/Security/frontend_login.html.twig', array(
  86. 'last_username' => $lastUsername,
  87. 'block' => false,
  88. // 'form' => $form->createView(),
  89. // 'error' => $error,
  90. ));
  91. }
  92. /**
  93. * @param Request $request
  94. * @return Response
  95. */
  96. public function ssiFrontendLoginFormAction(Request $request, $template = '@VisualMediaSecurity/Security/frontend_login_form.html.twig', $redirect_url = null): Response
  97. {
  98. $masterRequest = $this->get('request_stack')->getMasterRequest();
  99. $authenticationUtils = $this->get(AuthenticationUtils::class);
  100. $lastUsername = $authenticationUtils->getLastUsername();
  101. $error = $authenticationUtils->getLastAuthenticationError();
  102. $request->attributes->set('template', $template);
  103. $request->attributes->set('redirect_url', $redirect_url);
  104. $form = $this->createForm(FrontendLoginType::class, array(
  105. '_username' => $lastUsername,
  106. LoginHandler::RETURN_URL => $redirect_url,
  107. ));
  108. $form->handleRequest($masterRequest);
  109. return $this->render($template, array(
  110. 'error' => $error,
  111. 'form' => $form->createView(),
  112. 'last_username' => $lastUsername,
  113. 'block' => false,
  114. ));
  115. }
  116. }