bundles/Sintra/CMSCoreBundle/Controller/AccountController.php line 31

Open in your IDE?
  1. <?php
  2. namespace Sintra\CMSCoreBundle\Controller;
  3. use CustomerManagementFrameworkBundle\Security\OAuth\Exception\AccountNotLinkedException;
  4. use Pimcore\Controller\FrontendController;
  5. use Pimcore\Model\DataObject\Customer;
  6. use Sintra\CMSCoreBundle\Form\LoginFormType;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  13. /**
  14.  * @Route("/account")
  15.  */
  16. class AccountController extends FrontendController
  17. {
  18.     /**
  19.      * @Route("/login", name="account-login")
  20.      *
  21.      * @param AuthenticationUtils $authenticationUtils
  22.      * @param SessionInterface $session
  23.      * @param Request $request
  24.      * @param UserInterface|null $user
  25.      *
  26.      * @return Response|RedirectResponse
  27.      */
  28.     public function loginAction(
  29.         AuthenticationUtils $authenticationUtils,
  30.         SessionInterface $session,
  31.         Request $request,
  32.         UserInterface $user null
  33.     ) {
  34.         //redirect user to index page if logged in
  35.         if ($user && $this->isGranted('ROLE_USER')) {
  36.             return $this->redirectToRoute('home');
  37.         }
  38.         // get the login error if there is one
  39.         $error $authenticationUtils->getLastAuthenticationError();
  40.         // OAuth handling - the OAuth authenticator is configured to return to the login page on errors
  41.         // (see failure_path configuration) - therefore we can fetch the last authentication error
  42.         // here. If the error is an AccountNotLinkedException (as thrown by our user provider) save the
  43.         // OAuth token to the session and redirect to registration with a special key which can be used
  44.         // to load the token to prepopulate the registration form with account data.
  45.         if ($error instanceof AccountNotLinkedException) {
  46.             //TO-DO if needed
  47.         }
  48.         // last username entered by the user
  49.         $lastUsername $authenticationUtils->getLastUsername();
  50.         $formData = [
  51.             '_username' => $lastUsername
  52.         ];
  53.         $form $this->createForm(LoginFormType::class, $formData, [
  54.             'action' => $this->generateUrl('account-login'),
  55.         ]);
  56.         $template $this->getLoginTemplate();
  57.         $locale $request->get("locale");
  58.         return $this->render($template, [
  59.             'form' => $form->createView(),
  60.             'error' => $error,
  61.             'hideBreadcrumbs' => true,
  62.             'locale' => $locale
  63.         ]);
  64.     }
  65.     private function getLoginTemplate()
  66.     {
  67.         if (file_exists(PIMCORE_PROJECT_ROOT "/templates/account/login.html.twig")) {
  68.             return "/account/login.html.twig";
  69.         }
  70.         return "@SintraCMSCore/account/login.html.twig";
  71.     }
  72. }