src/Controller/SecurityController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  8. use App\Entity\User;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
  11. use Symfony\Component\Security\Csrf\CsrfToken;
  12. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  13. use Symfony\Component\Validator\Constraints\DateTime;
  14. class SecurityController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/login", name="app_login")
  18.      */
  19.     public function login(AuthenticationUtils $authenticationUtils): Response
  20.     {
  21.         // if ($this->getUser()) {
  22.         //     return $this->redirectToRoute('target_path');
  23.         // }
  24.         // get the login error if there is one
  25.         $error $authenticationUtils->getLastAuthenticationError();
  26.         // last username entered by the user
  27.         $lastUsername $authenticationUtils->getLastUsername();
  28.         return $this->render('security/login2.html.twig', ['last_username' => $lastUsername'error' => $error]);
  29.     }
  30.     /**
  31.      * @Route("/student", name="app_login_student")
  32.      */
  33.     public function loginStudent(Request $requestCsrfTokenManagerInterface $csrfTokenManager): Response
  34.     {
  35.         $token = new CsrfToken('authenticate'$request->request->get('csrf_token'));
  36.         if (!$csrfTokenManager->isTokenValid($token)) {
  37.             throw new InvalidCsrfTokenException();
  38.         }
  39.         dd("ersgrg");
  40.         $username $request->request->get("username");
  41.         $password $request->request->get("password");
  42.         
  43.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  44.     }
  45.     /**
  46.      * @Route("/register", name="app_register")
  47.      */
  48.     public function register(UserPasswordEncoderInterface $userPasswordEncoderInterface): Response
  49.     {
  50.         // if ($this->getUser()) {
  51.         //     return $this->redirectToRoute('target_path');
  52.         // }
  53.         return $this->render('security/login.html.twig', ['last_username' => "cvc "'error' => "sdfes"]);
  54.     }
  55.     /**
  56.      * @Route("/logout", name="app_logout")
  57.      */
  58.     public function logout()
  59.     {
  60.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  61.     }
  62. }