src/Controller/SecurityController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Repository\UserRepository;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  11. class SecurityController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/login", name="app_login")
  15.      */
  16.     public function login(AuthenticationUtils $authenticationUtils): Response
  17.     {
  18.         if ($this->getUser()) {
  19.             return $this->redirectToRoute('app_admin_devis');
  20.         }
  21.         // get the login error if there is one
  22.         $error $authenticationUtils->getLastAuthenticationError();
  23.         // last username entered by the user
  24.         $lastUsername $authenticationUtils->getLastUsername();
  25.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  26.     }
  27.     /**
  28.      * @Route("/logout", name="app_logout")
  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.         /**
  35.      * @Route("/user/add", name="app_user_add")
  36.      */
  37.     public function addUser(
  38.         UserRepository $ur
  39.         EntityManagerInterface $em,
  40.         UserPasswordHasherInterface $hasher
  41.     ){
  42.         $user = new User();
  43.         $user->setEmail("contact@teko-consulting.com");
  44.         $user->setRoles(['ROLE_SUPER_ADMIN']);
  45.         $password $hasher->hashPassword($user'devis_facture1234');
  46.         $user->setPassword($password);
  47.         $em->persist($user);
  48.         $em->flush();
  49.         dd('user ajouté');
  50.     }
  51. }