From a79caf705db62fefd826058aa5aa118eb827521f Mon Sep 17 00:00:00 2001 From: sermandm Date: Sun, 13 Apr 2025 19:22:46 +0200 Subject: [PATCH] =?UTF-8?q?login=20fonctionnel,=20redirection=20selon=20le?= =?UTF-8?q?=20r=C3=B4le=20et=20d=C3=A9but=20de=20tableau=20de=20bord=20pou?= =?UTF-8?q?r=20le=20r=C3=B4le=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/HegreEtConfort.iml | 1 - assets/styles/css/app.css | 4 + config/packages/security.yaml | 89 +++++++++---------- src/Controller/CalendrierController.php | 13 +++ src/Controller/DashboardController.php | 29 ++++++ src/Controller/FaultController.php | 2 +- src/Controller/InterventionController.php | 2 +- src/Controller/SkillController.php | 2 +- src/Controller/StockController.php | 2 +- src/Controller/UserController.php | 2 +- src/Controller/VehicleController.php | 2 +- .../CustomAuthenticationSuccessHandler.php | 32 +++++++ templates/base.html.twig | 57 +++++++++--- templates/dashboard/admin.html.twig | 7 ++ templates/dashboard/chaffagiste.html.twig | 7 ++ templates/dashboard/secretaire.html.twig | 7 ++ 16 files changed, 196 insertions(+), 62 deletions(-) create mode 100644 src/Controller/DashboardController.php create mode 100644 src/Security/CustomAuthenticationSuccessHandler.php create mode 100644 templates/dashboard/admin.html.twig create mode 100644 templates/dashboard/chaffagiste.html.twig create mode 100644 templates/dashboard/secretaire.html.twig diff --git a/.idea/HegreEtConfort.iml b/.idea/HegreEtConfort.iml index af6cce8..f4221e4 100644 --- a/.idea/HegreEtConfort.iml +++ b/.idea/HegreEtConfort.iml @@ -3,7 +3,6 @@ - diff --git a/assets/styles/css/app.css b/assets/styles/css/app.css index de8f662..7ecbc0e 100644 --- a/assets/styles/css/app.css +++ b/assets/styles/css/app.css @@ -1,3 +1,7 @@ body { background: url("../image/fond.png") center center / cover no-repeat !important; + font-family: Arial, sans-serif; + margin: 0; + padding: 0; } + diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 7006ae0..5ad39df 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,51 +1,50 @@ security: - # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords - password_hashers: - Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' - # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider - providers: - # used to reload user from session & other features (e.g. switch_user) - app_user_provider: - entity: - class: App\Entity\Utilisateur - property: email - firewalls: - main: - lazy: true - provider: app_user_provider - form_login: - login_path: _login - check_path: _login - enable_csrf: true - csrf_token_id: authenticate - logout: - path: _logout - target: _login + # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords + password_hashers: + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' + # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider + providers: + # used to reload user from session & other features (e.g. switch_user) + app_user_provider: + entity: + class: App\Entity\Utilisateur + property: email + firewalls: + main: + lazy: true + provider: app_user_provider + form_login: + login_path: _login + check_path: _login + success_handler: App\Security\CustomAuthenticationSuccessHandler + enable_csrf: true + csrf_token_id: authenticate + logout: + path: _logout + target: _login + # activate different ways to authenticate + # https://symfony.com/doc/current/security.html#the-firewall + # https://symfony.com/doc/current/security/impersonating_user.html + # switch_user: true - - # activate different ways to authenticate - # https://symfony.com/doc/current/security.html#the-firewall - - # https://symfony.com/doc/current/security/impersonating_user.html - # switch_user: true - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - - { path: ^/admin, roles: ROLE_ADMIN } - - { path: ^/profile, roles: ROLE_USER } + # Easy way to control access for large sections of your site + # Note: Only the *first* access control that matches will be used + access_control: + - { path: ^/admin, roles: ROLE_ADMIN } + - { path: ^/secretaire, roles: ROLE_SECRETAIRE } + - { path: ^/chauffagiste, roles: ROLE_CHAUFFAGISTE } when@test: - security: - password_hashers: - # By default, password hashers are resource intensive and take time. This is - # important to generate secure password hashes. In tests however, secure hashes - # are not important, waste resources and increase test times. The following - # reduces the work factor to the lowest possible values. - Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: - algorithm: auto - cost: 4 # Lowest possible value for bcrypt - time_cost: 3 # Lowest possible value for argon - memory_cost: 10 # Lowest possible value for argon + security: + password_hashers: + # By default, password hashers are resource intensive and take time. This is + # important to generate secure password hashes. In tests however, secure hashes + # are not important, waste resources and increase test times. The following + # reduces the work factor to the lowest possible values. + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: + algorithm: auto + cost: 4 # Lowest possible value for bcrypt + time_cost: 3 # Lowest possible value for argon + memory_cost: 10 # Lowest possible value for argon diff --git a/src/Controller/CalendrierController.php b/src/Controller/CalendrierController.php index 3fc2c78..b080795 100644 --- a/src/Controller/CalendrierController.php +++ b/src/Controller/CalendrierController.php @@ -15,4 +15,17 @@ class CalendrierController extends AbstractController 'controller_name' => 'CalendrierController', ]); } + + #[Route('/calendrier/secretaire', name: 'calendrier_index_secretaire')] + public function indexSecretaire(): Response + { + return $this->render('calendrier/indexSecretaire.html.twig'); + } + + #[Route('/calendrier/chauffagiste', name: 'calendrier_index_chauffagiste')] + public function indexChauffagiste(): Response + { + return $this->render('calendrier/indexChauffagiste.html.twig'); + } + } diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php new file mode 100644 index 0000000..e4c59ac --- /dev/null +++ b/src/Controller/DashboardController.php @@ -0,0 +1,29 @@ +render('dashboard/admin.html.twig'); + } + + #[Route('/secretaire/dashboard', name: 'secretaire_dashboard')] + public function secretaire(): Response + { + return $this->render('dashboard/secretaire.html.twig'); + } + + #[Route('/chauffagiste/dashboard', name: 'chauffagiste_dashboard')] + public function chauffagiste(): Response + { + return $this->render('dashboard/chauffagiste.html.twig'); + } +} + diff --git a/src/Controller/FaultController.php b/src/Controller/FaultController.php index bb1f2d9..e74966d 100644 --- a/src/Controller/FaultController.php +++ b/src/Controller/FaultController.php @@ -17,7 +17,7 @@ final class FaultController extends AbstractController #[Route(name: 'app_fault_index', methods: ['GET'])] public function index(FaultRepository $faultRepository): Response { - return $this->render('fault/index.html.twig', [ + return $this->render('fault/admin.html.twig', [ 'faults' => $faultRepository->findAll(), ]); } diff --git a/src/Controller/InterventionController.php b/src/Controller/InterventionController.php index 11cce71..e71c7eb 100644 --- a/src/Controller/InterventionController.php +++ b/src/Controller/InterventionController.php @@ -17,7 +17,7 @@ final class InterventionController extends AbstractController #[Route(name: 'app_intervention_index', methods: ['GET'])] public function index(InterventionRepository $interventionRepository): Response { - return $this->render('intervention/index.html.twig', [ + return $this->render('intervention/admin.html.twig', [ 'interventions' => $interventionRepository->findAll(), ]); } diff --git a/src/Controller/SkillController.php b/src/Controller/SkillController.php index 2d2adac..1cc04d1 100644 --- a/src/Controller/SkillController.php +++ b/src/Controller/SkillController.php @@ -17,7 +17,7 @@ final class SkillController extends AbstractController #[Route(name: 'app_skill_index', methods: ['GET'])] public function index(SkillRepository $skillRepository): Response { - return $this->render('skill/index.html.twig', [ + return $this->render('skill/admin.html.twig', [ 'skills' => $skillRepository->findAll(), ]); } diff --git a/src/Controller/StockController.php b/src/Controller/StockController.php index 0252e71..cb706c0 100644 --- a/src/Controller/StockController.php +++ b/src/Controller/StockController.php @@ -17,7 +17,7 @@ final class StockController extends AbstractController #[Route(name: 'app_stock_index', methods: ['GET'])] public function index(StockRepository $stockRepository): Response { - return $this->render('stock/index.html.twig', [ + return $this->render('stock/admin.html.twig', [ 'stocks' => $stockRepository->findAll(), ]); } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 516ff1f..00b867f 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -17,7 +17,7 @@ final class UserController extends AbstractController #[Route(name: 'app_user_index', methods: ['GET'])] public function index(UserRepository $userRepository): Response { - return $this->render('user/index.html.twig', [ + return $this->render('user/admin.html.twig', [ 'users' => $userRepository->findAll(), ]); } diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index 4921a28..edc5963 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -17,7 +17,7 @@ final class VehicleController extends AbstractController #[Route(name: 'app_vehicle_index', methods: ['GET'])] public function index(VehicleRepository $vehicleRepository): Response { - return $this->render('vehicle/index.html.twig', [ + return $this->render('vehicle/admin.html.twig', [ 'vehicles' => $vehicleRepository->findAll(), ]); } diff --git a/src/Security/CustomAuthenticationSuccessHandler.php b/src/Security/CustomAuthenticationSuccessHandler.php new file mode 100644 index 0000000..ad5783e --- /dev/null +++ b/src/Security/CustomAuthenticationSuccessHandler.php @@ -0,0 +1,32 @@ +router = $router; + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token): RedirectResponse + { + $user = $token->getUser(); + $roles = $user->getRoles(); + + return match (true) { + in_array('ROLE_ADMIN', $roles) => new RedirectResponse($this->router->generate('admin_dashboard')), + in_array('ROLE_SECRETAIRE', $roles) => new RedirectResponse($this->router->generate('secretaire_dashboard')), + in_array('ROLE_CHAUFFAGISTE', $roles) => new RedirectResponse($this->router->generate('chauffagiste_dashboard')), + default => new RedirectResponse($this->router->generate('_login')), + }; + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index c71b178..269eeb4 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -2,16 +2,53 @@ - {% block title %}Welcome!{% endblock %} - - {% block stylesheets %} - {% endblock %} - - {% block javascripts %} - {% block importmap %}{{ importmap('app') }}{% endblock %} - {% endblock %} + {% block title %}Mon App Symfony{% endblock %} + {% block stylesheets %}{% endblock %} -{% block body %}{% endblock %} + +{% if app.user %} + + +{% endif %} + +
+ {% block body %}{% endblock %} +
+ +{% block javascripts %}{% endblock %} - \ No newline at end of file + diff --git a/templates/dashboard/admin.html.twig b/templates/dashboard/admin.html.twig new file mode 100644 index 0000000..2eea202 --- /dev/null +++ b/templates/dashboard/admin.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Bienvenue Admin

+

Tu as tous les droits ici !

+{% endblock %} + diff --git a/templates/dashboard/chaffagiste.html.twig b/templates/dashboard/chaffagiste.html.twig new file mode 100644 index 0000000..05d8115 --- /dev/null +++ b/templates/dashboard/chaffagiste.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Bienvenue chauffagiste

+

Vas travailler

+{% endblock %} + diff --git a/templates/dashboard/secretaire.html.twig b/templates/dashboard/secretaire.html.twig new file mode 100644 index 0000000..8c9281a --- /dev/null +++ b/templates/dashboard/secretaire.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Bienvenue Secretaire

+

Fais ce que tu veux

+{% endblock %} +