src/Controller/SecurityController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/", name="app_login")
  12.      */
  13.     public function login(AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         /*$em = $this->getDoctrine()->getManager();
  16.         $user = new User();
  17.         $user->setUsername('chintan');
  18.         $user->setEmail('chintan.mirani@gmail.com');
  19.         $user->setRoles(array('ROLE_ADMIN'));
  20.         $user->setPassword('123456');
  21.         $user->setCreatedAt(new \DateTime());
  22.         $user->setUpdatedAt(new \DateTime());
  23.         $em->persist($user);
  24.         $em->flush();
  25.         echo "string";exit();*/
  26.         // if ($this->getUser()) {
  27.         //     return $this->redirectToRoute('target_path');
  28.         // }
  29.         // Update record
  30.         /*$em = $this->getDoctrine()->getManager();
  31.         $userData = $em->getRepository(User::class)
  32.                 ->find(2);
  33.         $userData->setRoles(array('ROLE_ADMIN'));
  34.         $em->persist($userData);
  35.         $em->flush();*/
  36.         // get the login error if there is one
  37.         $error $authenticationUtils->getLastAuthenticationError();
  38.         // last username entered by the user
  39.         $lastUsername $authenticationUtils->getLastUsername();
  40.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  41.     }
  42.     /**
  43.      * @Route("/logout", name="app_logout")
  44.      */
  45.     public function logout()
  46.     {
  47.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  48.     }
  49. }