<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Validator\Constraints\DateTime;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login2.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/student", name="app_login_student")
*/
public function loginStudent(Request $request, CsrfTokenManagerInterface $csrfTokenManager): Response
{
$token = new CsrfToken('authenticate', $request->request->get('csrf_token'));
if (!$csrfTokenManager->isTokenValid($token)) {
throw new InvalidCsrfTokenException();
}
dd("ersgrg");
$username = $request->request->get("username");
$password = $request->request->get("password");
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/register", name="app_register")
*/
public function register(UserPasswordEncoderInterface $userPasswordEncoderInterface): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
return $this->render('security/login.html.twig', ['last_username' => "cvc ", 'error' => "sdfes"]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
}