src/Controller/SecurityController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\UserType;
  4. use Detection\MobileDetect;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. class SecurityController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/", name="app_login")
  16.      * @param AuthenticationUtils $authenticationUtils
  17.      * @return Response
  18.      */
  19.     public function login(AuthenticationUtils $authenticationUtils): Response
  20.     {
  21.          if ($this->getUser()) {
  22.              return $this->redirectToRoute('projet_list');
  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/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  29.     }
  30.     /**
  31.      * @Route("/logout", name="app_logout")
  32.      */
  33.     public function logout()
  34.     {
  35.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  36.     }
  37.     /**
  38.      * @Route("/update",name="user_update")
  39.      * @param Request $request
  40.      * @param EntityManagerInterface $manager
  41.      * @return Response
  42.      */
  43.     public function update(Request $request,UserPasswordEncoderInterface $encoderEntityManagerInterface $manager)
  44.     {
  45.         $detect = new MobileDetect();
  46.         $user $this->getUser();
  47.         $userForm $this->createForm(UserType::class,$user);
  48.         $userForm->handleRequest($request);
  49.         if ($userForm->isSubmitted() && $userForm->isValid())
  50.         {
  51.             $password $encoder->encodePassword($user,$user->getPassword());
  52.             $user->setPassword($password);
  53.             $manager->persist($user);
  54.             $manager->flush();
  55.             return $this->redirectToRoute('projet_list');
  56.         }
  57.         return $this->render('security/updateUser.html.twig',[
  58.             'form'=>$userForm->createView(),
  59.             'mobile'=>($detect->isMobile()||$detect->isTablet())
  60.         ]);
  61.     }
  62. }