src/Controller/SecurityController.php line 26

Open in your IDE?
  1. <?php
  2. // src/Controller/RegistrationController.php
  3. namespace App\Controller;
  4. use App\Entity\AppUser;
  5. use App\Form\RegistrationFormType;
  6. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  13. /**
  14.  * @Route("/{_locale}")
  15.  */
  16. class SecurityController extends AbstractController
  17. {
  18.     
  19.     /**
  20.      * @Route("/login", name="security_login")
  21.      * @return \Symfony\Component\HttpFoundation\Response
  22.     */
  23.     public function login(Request $requestUserPasswordHasherInterface $passwordHasherAuthenticationUtils $authenticationUtils)
  24.     {
  25.         
  26.         $error '';
  27.         $lastUsername '';
  28.             
  29.             $error $authenticationUtils->getLastAuthenticationError();
  30.             $lastUsername $authenticationUtils->getLastUsername();
  31.             
  32.             
  33.         
  34.         return $this->render('security/login.html.twig', [
  35.             'error' => $error,
  36.             'last_username' => $lastUsername,
  37.         ]);
  38.     }
  39.     
  40.     /**
  41.      * @Route("/check", name="security.check")
  42.      * @return \Symfony\Component\HttpFoundation\Response
  43.     */
  44.     public function check(Request $requestUserPasswordHasherInterface $passwordHasher)
  45.     {
  46.         
  47.         if($request->getMethod() == 'POST'){
  48.             $form->handleRequest($request);
  49.             if($form->isSubmitted()){
  50.                 if($form->isValid()){
  51.                     
  52.                     
  53.                 }
  54.             }
  55.         }
  56.         
  57.         return $this->render('security/login.html.twig', [ 
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/changer-passe", name="security_changer_passe")
  62.      * @return \Symfony\Component\HttpFoundation\Response
  63.     */
  64.     public function changerPasseAction(Request $requestUserPasswordHasherInterface $passwordHasher)
  65.     {
  66.         $em $this->getDoctrine()
  67.                     ->getManager();
  68.         if($request->getMethod() == 'POST'){
  69.             
  70.             $email $request->request->get('email');
  71.             $password $request->request->get('password'); 
  72.             
  73.             $user $em->getRepository(AppUser::class)
  74.                         ->findOneByEmail($email);
  75.                         
  76.             //Effacer l'ancien mot de passe
  77.             $user->setPassword('');
  78.             $hashedPassword $passwordHasher->hashPassword($user$password);
  79.             $user->setPassword($hashedPassword);
  80.             $em->flush();
  81.             
  82.         }
  83.         
  84.         return $this->render('security/changer_passe.html.twig', [ 
  85.         ]);
  86.     }
  87.     
  88.     /**
  89.      * @Route("/logout", name="security_logout")
  90.      * @return \Symfony\Component\HttpFoundation\Response
  91.     */
  92.     /*
  93.     public function logout(Request $request)
  94.     {
  95.         
  96.         
  97.         return $this->render('security/login.html.twig', [ 
  98.         ]);
  99.     }
  100.     */
  101. }