src/Controller/SecurityController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\AccessToken\AccessTokenService;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends BaseAbstractController
  9. {
  10.     public function login(AuthenticationUtils $authenticationUtils): Response
  11.     {
  12.         if ($this->getUser()) {
  13.             return $this->redirectToRoute('index');
  14.         }
  15.         $error $authenticationUtils->getLastAuthenticationError();
  16.         $lastUsername $authenticationUtils->getLastUsername();
  17.         if ($error) {
  18.             switch ($error->getMessage()) {
  19.                 case "The presented password is invalid.":
  20.                     $error 'Неверный логин или пароль';
  21.                     break;
  22.                 default:
  23.                     $error $error->getMessage();
  24.             }
  25.             //  $this->addFlash('errors', $error->getMessage());
  26.              $this->addFlash('errors'$error);
  27.         }
  28.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername]);
  29.     }
  30.     public function logout(): void
  31.     {
  32.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  33.     }
  34.     public function messengerLogout(AccessTokenService $accessTokenServiceSession $session): Response
  35.     {
  36.         $token $accessTokenService->getByCookies();
  37.         if ($token) {
  38.             $token->setRevoked(true);
  39.             if ($token->getRefreshToken()) {
  40.                 $token->getRefreshToken()->setRevoked(true);
  41.             }
  42.             $this->em->flush();
  43.         }
  44.         if ($this->getLoggedInUser()) {
  45.             $session->invalidate();
  46.             $this->container->get('security.token_storage')->setToken(null);
  47.         }
  48.         $response $this->redirectToRoute('messenger_login');
  49.         $response->headers->clearCookie('access_token''/1bc3f6fdaea8f6ae35');
  50.         return $response;
  51. //        throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  52.     }
  53.     public function messengerLogin(AuthenticationUtils $authenticationUtils): Response
  54.     {
  55.         if ($this->getUser()) {
  56.             return $this->redirectToRoute('messenger_index');
  57.         }
  58.         $error $authenticationUtils->getLastAuthenticationError();
  59.         $lastUsername $authenticationUtils->getLastUsername();
  60.         if ($error) {
  61.             switch ($error->getMessage()) {
  62.                 case "Bad credentials.":
  63.                     $error 'Неверный логин или пароль.';
  64.                     break;
  65.                 default:
  66.                     $error $error->getMessage();
  67.             }
  68.             $this->addFlash('errors'$error);
  69.         }
  70.         return $this->render('messenger/login.html.twig', [
  71.             'last_username' => $lastUsername
  72.         ]);
  73.     }
  74. }