Update controllers

This commit is contained in:
2024-11-29 21:46:33 -05:00
parent 9a0b4db460
commit eac41ac9fc
4 changed files with 223 additions and 33 deletions

View File

@ -3,14 +3,31 @@
namespace App\Controller;
use App\Entity\User;
use App\Form\UserFormType;
use Doctrine\ORM\EntityManagerInterface;
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 Symfony\Component\Security\Http\Attribute\CurrentUser;
class DefaultController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly UserPasswordHasherInterface $userPasswordHasher,
private array $navLinks = []
) {
$this->navLinks = [
'admin_dashboard' => 'nav-link text-dark',
'user_dashboard' => 'nav-link text-dark',
'profile' => 'nav-link text-dark',
'user_list' => 'nav-link text-dark',
];
}
#[Route('/dashboard', name: 'app_dashboard')]
public function dashboard(Request $request, #[CurrentUser()] ?User $user): Response
{
@ -20,11 +37,41 @@ class DefaultController extends AbstractController
return $this->redirectToRoute('app_register_step', ['step' => RegistrationController::REGISTER_STEP_TWO]);
}
$this->navLinks['user_dashboard'] = 'nav-link text-white active bg-gradient-dark';
return $this->render(
'internal/dashboard.html.twig',
[
'user' => $user
]
array_merge(
$this->navLinks,
[
'breadcrumbs' => [
'Dashboard'
],
'notifications' => $user->retrieveUnreadNotifications(),
]
)
);
}
#[Route('/profile', name: 'app_profile')]
public function profile(#[CurrentUser()] User $user): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->navLinks['profile'] = 'nav-link text-white active bg-gradient-dark';
return $this->render(
'internal/profile.html.twig',
array_merge(
$this->navLinks,
[
'breadcrumbs' => [
'Profile'
],
'notifications' => $user->retrieveUnreadNotifications(),
]
)
);
}
}