vendor/sulu/community-bundle/Controller/LoginController.php line 30

  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\CommunityBundle\Controller;
  11. use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration;
  12. use Sulu\Bundle\HttpCacheBundle\Cache\SuluHttpCache;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  16. /**
  17.  * Handles Login and login embed page.
  18.  */
  19. class LoginController extends AbstractController
  20. {
  21.     public const TYPE Configuration::TYPE_LOGIN;
  22.     /**
  23.      * Show Login page.
  24.      */
  25.     public function indexAction(Request $request): Response
  26.     {
  27.         $authenticationUtils $this->getAuthenticationUtils();
  28.         // get the login error if there is one
  29.         $error $authenticationUtils->getLastAuthenticationError();
  30.         // last username entered by the user
  31.         $lastUsername $authenticationUtils->getLastUsername();
  32.         return $this->renderTemplate(Configuration::TYPE_LOGIN, [
  33.             'last_username' => $lastUsername,
  34.             'error' => $error,
  35.         ]);
  36.     }
  37.     /**
  38.      * ESI Action to show user on every page.
  39.      */
  40.     public function embedAction(Request $request): Response
  41.     {
  42.         $communityManager $this->getCommunityManager($this->getWebspaceKey());
  43.         $maintenance $communityManager->getConfigTypeProperty(Configuration::MAINTENANCEConfiguration::ENABLED);
  44.         $response $this->render(
  45.             $communityManager->getConfigTypeProperty(self::TYPEConfiguration::EMBED_TEMPLATE),
  46.             [
  47.                 'maintenanceMode' => $maintenance,
  48.             ]
  49.         );
  50.         $response->setPrivate();
  51.         $response->setMaxAge(0);
  52.         $response->setSharedMaxAge(0);
  53.         $response->headers->addCacheControlDirective('must-revalidate'true);
  54.         $response->headers->addCacheControlDirective('no-store'true);
  55.         $response->headers->set(SuluHttpCache::HEADER_REVERSE_PROXY_TTL'0');
  56.         return $response;
  57.     }
  58.     protected function getAuthenticationUtils(): AuthenticationUtils
  59.     {
  60.         return $this->container->get('security.authentication_utils');
  61.     }
  62.     /**
  63.      * @return array<string|int, string>
  64.      */
  65.     public static function getSubscribedServices(): array
  66.     {
  67.         $subscribedServices parent::getSubscribedServices();
  68.         $subscribedServices['security.authentication_utils'] = AuthenticationUtils::class;
  69.         return $subscribedServices;
  70.     }
  71. }