<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Controller;
use App\Form\Type\ChangePasswordType;
use App\Form\UserType;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\UserRepository;
/**
* Controller used to manage current user.
*
* @author Romain Monteil <monteil.romain@gmail.com>
*/
#[Route('/profile'), IsGranted('ROLE_USER')]
class UserController extends AbstractController {
#[Route('/edit-password', methods: ['GET', 'POST'], name: 'edit_password')]
public function editPassword(Request $request, EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher): Response {
if ($request->isMethod('post')) {
// create the user and hash its password
$user = $this->getUser();
$hashedPassword = $passwordHasher->hashPassword($user, $request->get('basic-default-password'));
$user->setPassword($hashedPassword);
$entityManager->persist($user);
$entityManager->flush();
$this->addFlash('success', 'Mot de passe modifié avec succées');
return $this->redirectToRoute('dashboard');
}
return $this->render('user/editPassword.html.twig', [
]);
}
#[Route('/dashboard', methods: ['GET', 'POST'], name: 'dashboard')]
public function dashboard(Request $request, UserRepository $users, EntityManagerInterface $entityManager): Response {
$accounts = count($users->findAll());
$invites = count($users->findInvites());
$colaborateurs = count($users->findColaborateurs());
$admins = count($users->findAdmins());
$agents = count($users->findAgents());
return $this->render('user/dashboard.html.twig', [
'accounts' => $accounts,
'invites' => $invites,
'colaborateurs' => $colaborateurs,
'admins' => $admins,
'agents' => $agents,
]);
}
}