src/Controller/UserController.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller;
  11. use App\Form\Type\ChangePasswordType;
  12. use App\Form\UserType;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use App\Repository\UserRepository;
  21. /**
  22.  * Controller used to manage current user.
  23.  *
  24.  * @author Romain Monteil <monteil.romain@gmail.com>
  25.  */
  26. #[Route('/profile'), IsGranted('ROLE_USER')]
  27. class UserController extends AbstractController {
  28.     #[Route('/edit-password', methods: ['GET', 'POST'], name: 'edit_password')]
  29.     public function editPassword(Request $request, EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher): Response {
  30.         if ($request->isMethod('post')) {
  31.             // create the user and hash its password
  32.             $user = $this->getUser();
  33.             $hashedPassword = $passwordHasher->hashPassword($user, $request->get('basic-default-password'));
  34.             $user->setPassword($hashedPassword);
  35.             $entityManager->persist($user);
  36.             $entityManager->flush();
  37.             $this->addFlash('success', 'Mot de passe modifié avec succées');
  38.             return $this->redirectToRoute('dashboard');
  39.         }
  40.         return $this->render('user/editPassword.html.twig', [
  41.         ]);
  42.     }
  43.     #[Route('/dashboard', methods: ['GET', 'POST'], name: 'dashboard')]
  44.     public function dashboard(Request $request, UserRepository $users, EntityManagerInterface $entityManager): Response {
  45.         $accounts = count($users->findAll());
  46.         $invites = count($users->findInvites());
  47.         $colaborateurs = count($users->findColaborateurs());
  48.         $admins = count($users->findAdmins());
  49.         $agents = count($users->findAgents());
  50.         return $this->render('user/dashboard.html.twig', [
  51.                     'accounts' => $accounts,
  52.                     'invites' => $invites,
  53.                     'colaborateurs' => $colaborateurs,
  54.                     'admins' => $admins,
  55.                     'agents' => $agents,
  56.         ]);
  57.     }
  58. }