src/Controller/SecurityController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\UserRepository;
  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. use App\Entity\ArticleSearch;
  9. use App\Entity\User;
  10. use App\Form\ArticleSearchType;
  11. use App\Form\RegistrationFormType;
  12. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
  15. class SecurityController extends AbstractController
  16. {
  17.     #[Route(path'/api/login'name:'api_login'methods:['POST'])]
  18.     public function apiLogin(){
  19.         $user $this->getUser();
  20.         return $this->json([
  21.             'username'=>$user->getUsername(),
  22.             'roles'=>$user->getRoles()
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/login", name="app_login")
  27.      */
  28.     public function login(AuthenticationUtils $authenticationUtilsUserRepository $userRepository): Response
  29.     {
  30.         if ($this->getUser()) {
  31.             return $this->redirectToRoute('home');
  32.         }
  33.         // get the login error if there is one
  34.         $error $authenticationUtils->getLastAuthenticationError();
  35.         // last username entered by the user
  36.         $lastUsername $authenticationUtils->getLastUsername();
  37.         // FORM DE CREATION DE COMPTE
  38.         $user = new User();
  39.         $registrationForm $this->createForm(RegistrationFormType::class,$user);
  40.         return $this->renderForm('security/index.html.twig', [
  41.             'last_username' => $lastUsername
  42.             'error' => $error,
  43.             'users'=>$userRepository->findAll(),
  44.             // 'form'=>$formSearch,
  45.             'registrationForm'=>$registrationForm
  46.         ]);
  47.     }
  48.         /**
  49.      * @Route("/login_check", name="login_check")
  50.      */
  51.     public function check()
  52.     {
  53.         throw new \LogicException('This code should never be reached');
  54.     }
  55.     /**
  56.      * @Route("/logout", name="app_logout")
  57.      */
  58.     public function logout()
  59.     {
  60.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  61.     }
  62. }