From aeb96e4b68afb044b4482b5dbb5bcc3801b89c7a Mon Sep 17 00:00:00 2001 From: ragueneaul Date: Thu, 21 Nov 2024 16:31:49 +0100 Subject: [PATCH 1/4] templates --- .idea/dataSources.xml | 12 ++++ .idea/workspace.xml | 33 +++++++++-- src/Controller/FaultController.php | 46 ++++++++++++--- src/Controller/InterventionController.php | 43 ++++++++++++-- src/Controller/LoginController.php | 18 ------ src/Controller/SkillController.php | 2 +- src/Controller/StockController.php | 64 +++++++++++++++++++-- src/Controller/UserController.php | 70 +++++++++++++++++++++-- src/Controller/VehicleController.php | 2 +- src/Form/FaultType.php | 28 +++++++++ src/Form/StockType.php | 33 +++++++++++ src/Form/UserType.php | 35 ++++++++++++ templates/fault/add.html.twig | 10 ++++ templates/fault/index.html.twig | 20 ------- templates/fault/list.html.twig | 9 +++ templates/stock/add.html.twig | 10 ++++ templates/stock/index.html.twig | 20 ------- templates/stock/list.html.twig | 11 ++++ templates/user/add.html.twig | 10 ++++ templates/user/index.html.twig | 20 ------- templates/user/list.html.twig | 14 +++++ 21 files changed, 401 insertions(+), 109 deletions(-) create mode 100644 .idea/dataSources.xml delete mode 100644 src/Controller/LoginController.php create mode 100644 src/Form/FaultType.php create mode 100644 src/Form/StockType.php create mode 100644 src/Form/UserType.php create mode 100644 templates/fault/add.html.twig delete mode 100644 templates/fault/index.html.twig create mode 100644 templates/fault/list.html.twig create mode 100644 templates/stock/add.html.twig delete mode 100644 templates/stock/index.html.twig create mode 100644 templates/stock/list.html.twig create mode 100644 templates/user/add.html.twig delete mode 100644 templates/user/index.html.twig create mode 100644 templates/user/list.html.twig diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..08c0eb6 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://172.20.96.1:5432/chauffageproj + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d042e16..966b661 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,18 @@ - + + + + + + + + + + + $PROJECT_DIR$/composer.json - + + + - + @@ -166,14 +178,20 @@ @@ -190,8 +208,8 @@ - @@ -206,6 +224,9 @@ + + + diff --git a/src/Controller/FaultController.php b/src/Controller/FaultController.php index 4267375..dc9d09a 100644 --- a/src/Controller/FaultController.php +++ b/src/Controller/FaultController.php @@ -2,17 +2,49 @@ namespace App\Controller; +use App\Entity\Fault; +use App\Form\FaultType; +use App\Repository\FaultRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; - +use Symfony\Component\Routing\Annotation\Route; class FaultController extends AbstractController { - #[Route('/fault', name: 'app_fault')] - public function index(): Response + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly FaultRepository $faultRepository + ) { - return $this->render('fault/index.html.twig', [ - 'controller_name' => 'FaultController', + } + #[Route('/fault/add', name: 'fault_add')] + public function add(Request $request): Response + { + $fault = new Fault(); + $form = $this->createForm(FaultType::class, $fault); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($fault); + $this->entityManager->flush(); + + return $this->redirectToRoute("app_fault_list"); + } + + return $this->render('fault/add.html.twig', [ + 'form' => $form, ]); } -} + + #[Route('/fault/list', name: 'fault_list')] + public function list(): Response + { + $fault = $this->faultRepository->findAll(); + + return $this->render('fault/list.html.twig', [ + 'fault' => $fault, + ]); + } +} \ No newline at end of file diff --git a/src/Controller/InterventionController.php b/src/Controller/InterventionController.php index 1f752e6..4c9b0c6 100644 --- a/src/Controller/InterventionController.php +++ b/src/Controller/InterventionController.php @@ -2,17 +2,50 @@ namespace App\Controller; +use App\Entity\Intervention; +use App\Form\InterventionType; +use App\Repository\InterventionRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class InterventionController extends AbstractController { - #[Route('/intervention', name: 'app_intervention')] - public function index(): Response + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly InterventionRepository $interventionRepository + ) { - return $this->render('intervention/index.html.twig', [ - 'controller_name' => 'InterventionController', + } + #[\Symfony\Component\Routing\Annotation\Route('/intervention/add', name: 'fault_add')] + public function add(Request $request): Response + { + $fault = new Intervention(); + $form = $this->createForm(InterventionType::class, $fault); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($fault); + $this->entityManager->flush(); + + return $this->redirectToRoute("app_fault_list"); + } + + return $this->render('fault/add.html.twig', [ + 'form' => $form, ]); } -} + + #[Route('/fault/list', name: 'fault_list')] + public function list(): Response + { + $fault = $this->faultRepository->findAll(); + + return $this->render('fault/list.html.twig', [ + 'fault' => $fault, + ]); + } +} \ No newline at end of file diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php deleted file mode 100644 index 4946695..0000000 --- a/src/Controller/LoginController.php +++ /dev/null @@ -1,18 +0,0 @@ -render('login/index.html.twig', [ - 'controller_name' => 'LoginController', - ]); - } -} diff --git a/src/Controller/SkillController.php b/src/Controller/SkillController.php index 810fb3c..c828d2a 100644 --- a/src/Controller/SkillController.php +++ b/src/Controller/SkillController.php @@ -11,7 +11,7 @@ class SkillController extends AbstractController #[Route('/skill', name: 'app_skill')] public function index(): Response { - return $this->render('skill/index.html.twig', [ + return $this->render('skill/add.html.twig', [ 'controller_name' => 'SkillController', ]); } diff --git a/src/Controller/StockController.php b/src/Controller/StockController.php index a0400ed..52df48c 100644 --- a/src/Controller/StockController.php +++ b/src/Controller/StockController.php @@ -2,17 +2,69 @@ namespace App\Controller; +use App\Entity\Stock; +use App\Form\StockType; +use App\Repository\StockRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\Annotation\Route; class StockController extends AbstractController { - #[Route('/stock', name: 'app_stock')] - public function index(): Response + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly StockRepository $stockRepository + ) { - return $this->render('stock/index.html.twig', [ - 'controller_name' => 'StockController', + } + + #[Route('/stock/add', name: 'stock_add')] + public function add(Request $request): Response + { + $stock = new Stock(); + $form = $this->createForm(StockType::class, $stock); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($stock); + $this->entityManager->flush(); + } + + return $this->render('stock/add.html.twig', [ + 'form' => $form, ]); } -} + + #[Route('/stock/list', name: 'stock_list')] + public function list(): Response + { + $stocks = $this->stockRepository->findAll(); + + return $this->render('stock/list.html.twig', [ + 'stocks' => $stocks, + ]); + } + + #[Route('/stock/update/{id}', name: 'stock_update')] + public function update(int $id, Request $request): Response + { + $stock = $this->stockRepository->find($id); + $form = $this->createForm(StockType::class, $stock); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($stock); + $this->entityManager->flush(); + } + + return $this->render('stock/add.html.twig', [ + 'form' => $form, + ]); + } + + +} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 25942d8..70588d5 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,17 +2,77 @@ namespace App\Controller; +use App\Entity\User; +use App\Form\UserType; +use App\Repository\UserRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\Annotation\Route; class UserController extends AbstractController { - #[Route('/user', name: 'app_user')] - public function index(): Response + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly UserRepository $userRepository + ) { - return $this->render('user/index.html.twig', [ - 'controller_name' => 'UserController', + } + + #[Route('/user/add', name: 'user_add')] + public function add(Request $request): Response + { + $user = new User(); + $form = $this->createForm(UserType::class, $user); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($user); + $this->entityManager->flush(); + } + + return $this->render('user/add.html.twig', [ + 'form' => $form, ]); } + + #[Route('/user/list', name: 'user_list')] + public function list(): Response + { + $users = $this->userRepository->findAll(); + + return $this->render('user/list.html.twig', [ + 'users' => $users, + ]); + } + + #[Route('/user/update/{id}', name: 'user_update')] + public function update(int $id, Request $request): Response + { + $user = $this->userRepository->find($id); + $form = $this->createForm(UserType::class, $user); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($user); + $this->entityManager->flush(); + } + + return $this->render('user/add.html.twig', [ + 'form' => $form, + ]); + } + + #[Route('/user/delete/{id}', name: '_delete')] + public function delete(int $id): Response + { + $user = $this->userRepository->find($id); + $this->entityManager->remove($user); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_user_list'); + } } diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index 80068bd..ffc6bf0 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -11,7 +11,7 @@ class VehicleController extends AbstractController #[Route('/vehicle', name: 'app_vehicle')] public function index(): Response { - return $this->render('vehicle/index.html.twig', [ + return $this->render('vehicle/add.html.twig', [ 'controller_name' => 'VehicleController', ]); } diff --git a/src/Form/FaultType.php b/src/Form/FaultType.php new file mode 100644 index 0000000..9960312 --- /dev/null +++ b/src/Form/FaultType.php @@ -0,0 +1,28 @@ +add('Wording', TextType::class) + ->add('save', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + // Configure your form options here + ]); + } +} diff --git a/src/Form/StockType.php b/src/Form/StockType.php new file mode 100644 index 0000000..a8480f7 --- /dev/null +++ b/src/Form/StockType.php @@ -0,0 +1,33 @@ +add('Wording', TextType::class) + ->add('Description', TextType::class) + ->add('Quantity', IntegerType::class) + ->add('save', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Stock::class, + ]); + } +} diff --git a/src/Form/UserType.php b/src/Form/UserType.php new file mode 100644 index 0000000..7bef9c4 --- /dev/null +++ b/src/Form/UserType.php @@ -0,0 +1,35 @@ +add('FirstName', TextType::class) + ->add('LastName', TextType::class) + ->add('BirthDate', DateType::class) + ->add('Email', EmailType::class) + ->add('Phone', TextType::class) + ->add('Type', TextType::class) + ->add('Save', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); + } +} diff --git a/templates/fault/add.html.twig b/templates/fault/add.html.twig new file mode 100644 index 0000000..601e2ec --- /dev/null +++ b/templates/fault/add.html.twig @@ -0,0 +1,10 @@ +{% extends 'base.html.twig' %} + +{% block title %}Ajouter une panne{% endblock %} + +{% block body %} +

Ajouter une panne

+ + {{ form(form) }} + +{% endblock %} diff --git a/templates/fault/index.html.twig b/templates/fault/index.html.twig deleted file mode 100644 index d3b62c1..0000000 --- a/templates/fault/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello FaultController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: -
    -
  • Your controller at E:/BTS/PhpStorm/HegreEtConfort/src/Controller/FaultController.php
  • -
  • Your template at E:/BTS/PhpStorm/HegreEtConfort/templates/fault/index.html.twig
  • -
-
-{% endblock %} diff --git a/templates/fault/list.html.twig b/templates/fault/list.html.twig new file mode 100644 index 0000000..1a84c39 --- /dev/null +++ b/templates/fault/list.html.twig @@ -0,0 +1,9 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello UserController!{% endblock %} + +{% block body %} + {% for user in users %} + {{ fault.Wording }} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/stock/add.html.twig b/templates/stock/add.html.twig new file mode 100644 index 0000000..0f684e5 --- /dev/null +++ b/templates/stock/add.html.twig @@ -0,0 +1,10 @@ +{% extends 'base.html.twig' %} + +{% block title %}Ajouter un utilisateur{% endblock %} + +{% block body %} +

Ajouter du stock

+ + {{ form(form) }} + +{% endblock %} diff --git a/templates/stock/index.html.twig b/templates/stock/index.html.twig deleted file mode 100644 index 72d4681..0000000 --- a/templates/stock/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello StockController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: -
    -
  • Your controller at E:/BTS/PhpStorm/HegreEtConfort/src/Controller/StockController.php
  • -
  • Your template at E:/BTS/PhpStorm/HegreEtConfort/templates/stock/index.html.twig
  • -
-
-{% endblock %} diff --git a/templates/stock/list.html.twig b/templates/stock/list.html.twig new file mode 100644 index 0000000..4cd9c76 --- /dev/null +++ b/templates/stock/list.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello StockController!{% endblock %} + +{% block body %} + {% for stock in stocks %} + {{ stock.Wording }} + {{ stock.Description }} + {{ stock.Quantity }} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/user/add.html.twig b/templates/user/add.html.twig new file mode 100644 index 0000000..3440b9d --- /dev/null +++ b/templates/user/add.html.twig @@ -0,0 +1,10 @@ +{# templates/user/add.html.twig #} +{% extends 'base.html.twig' %} + +{% block title %}Ajouter un utilisateur{% endblock %} + +{% block body %} +

Ajouter un utilisateur

+ + {{ form(form) }} +{% endblock %} diff --git a/templates/user/index.html.twig b/templates/user/index.html.twig deleted file mode 100644 index 1f43753..0000000 --- a/templates/user/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello UserController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: -
    -
  • Your controller at E:/BTS/PhpStorm/HegreEtConfort/src/Controller/UserController.php
  • -
  • Your template at E:/BTS/PhpStorm/HegreEtConfort/templates/user/index.html.twig
  • -
-
-{% endblock %} diff --git a/templates/user/list.html.twig b/templates/user/list.html.twig new file mode 100644 index 0000000..7477b1e --- /dev/null +++ b/templates/user/list.html.twig @@ -0,0 +1,14 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello UserController!{% endblock %} + +{% block body %} + {% for user in users %} + {{ user.FirstName }} + {{ user.LastName }} + {{ user.BirthDate|date("Y-m-d") }} + {{ user.Mail }} + {{ user.Phone }} + {{ user.Type }} + {% endfor %} +{% endblock %} \ No newline at end of file From ee236ff74aaac1882a825817d5ce8f692d3bdd0f Mon Sep 17 00:00:00 2001 From: ragueneaul Date: Thu, 21 Nov 2024 16:52:37 +0100 Subject: [PATCH 2/4] templates v2 --- .idea/dataSources.xml | 7 +++ .idea/workspace.xml | 43 +++++++---------- migrations/Version20241121154657.php | 70 ++++++++++++++++++++++++++++ templates/user/list.html.twig | 2 +- 4 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 migrations/Version20241121154657.php diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 08c0eb6..9b096cc 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -8,5 +8,12 @@ jdbc:postgresql://172.20.96.1:5432/chauffageproj $ProjectFileDir$ + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://172.20.96.1:5432/chauffageproj + $ProjectFileDir$ +
\ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 966b661..c33b8b6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,18 +5,7 @@
- - - - - - - - - - - - { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "develop", + "last_opened_file_path": "/home/ragueneaul@stsio.lan/Documents/DecoMaison_Lucas_Ragueneau", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" }, - "keyToStringList": { - "DatabaseDriversLRU": [ - "postgresql" + "keyToStringList": { + "DatabaseDriversLRU": [ + "postgresql" ] } -}]]> +} diff --git a/migrations/Version20241121154657.php b/migrations/Version20241121154657.php new file mode 100644 index 0000000..55567a9 --- /dev/null +++ b/migrations/Version20241121154657.php @@ -0,0 +1,70 @@ +addSql('CREATE SEQUENCE fault_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE intervention_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE skill_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE stock_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE "user_id_seq" INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE vehicle_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE fault (id INT NOT NULL, wording VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE intervention (id INT NOT NULL, wording VARCHAR(255) NOT NULL, timestamp TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, description VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, status VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE skill (id INT NOT NULL, wording VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE stock (id INT NOT NULL, wording VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, quantity VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE "user" (id INT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, birth_date DATE NOT NULL, email VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE vehicle (id INT NOT NULL, license_plate VARCHAR(255) NOT NULL, brand VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)'); + $this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)'); + $this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$ + BEGIN + PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text); + RETURN NEW; + END; + $$ LANGUAGE plpgsql;'); + $this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;'); + $this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP SEQUENCE fault_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE intervention_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE skill_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE stock_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE "user_id_seq" CASCADE'); + $this->addSql('DROP SEQUENCE vehicle_id_seq CASCADE'); + $this->addSql('DROP TABLE fault'); + $this->addSql('DROP TABLE intervention'); + $this->addSql('DROP TABLE skill'); + $this->addSql('DROP TABLE stock'); + $this->addSql('DROP TABLE "user"'); + $this->addSql('DROP TABLE vehicle'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/templates/user/list.html.twig b/templates/user/list.html.twig index 7477b1e..e48b70b 100644 --- a/templates/user/list.html.twig +++ b/templates/user/list.html.twig @@ -7,7 +7,7 @@ {{ user.FirstName }} {{ user.LastName }} {{ user.BirthDate|date("Y-m-d") }} - {{ user.Mail }} + {{ user.Email }} {{ user.Phone }} {{ user.Type }} {% endfor %} From e8baf76ad0fe00685fdbebcf4c01834d30863869 Mon Sep 17 00:00:00 2001 From: Maxiser Date: Thu, 28 Nov 2024 14:01:51 +0100 Subject: [PATCH 3/4] 1 --- .idea/dataSources.xml | 19 ++++ .idea/workspace.xml | 19 +++- config/packages/security.yaml | 8 +- migrations/Version20241114151456.php | 43 ++++++++ src/Entity/User.php | 159 ++++++++++++++++++++------- src/Repository/UserRepository.php | 19 +++- 6 files changed, 218 insertions(+), 49 deletions(-) create mode 100644 .idea/dataSources.xml create mode 100644 migrations/Version20241114151456.php diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..a32a582 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,19 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://172.20.96.1:5432/ + $ProjectFileDir$ + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://127.0.0.1:3306/hegreconfort + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d042e16..6152663 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,10 @@ - + + + @@ -190,8 +200,8 @@ - @@ -206,6 +216,7 @@ + diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 367af25..fbfb8ed 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -4,14 +4,18 @@ security: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: - users_in_memory: { memory: null } + # used to reload user from session & other features (e.g. switch_user) + app_user_provider: + entity: + class: App\Entity\User + property: email firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: lazy: true - provider: users_in_memory + provider: app_user_provider # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall diff --git a/migrations/Version20241114151456.php b/migrations/Version20241114151456.php new file mode 100644 index 0000000..34acab8 --- /dev/null +++ b/migrations/Version20241114151456.php @@ -0,0 +1,43 @@ +addSql('CREATE TABLE fault (id INT AUTO_INCREMENT NOT NULL, wording VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE intervention (id INT AUTO_INCREMENT NOT NULL, wording VARCHAR(255) NOT NULL, timestamp DATETIME NOT NULL, description VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, status VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE skill (id INT AUTO_INCREMENT NOT NULL, wording VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE stock (id INT AUTO_INCREMENT NOT NULL, wording VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, quantity VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, birth_date DATE NOT NULL, email VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE vehicle (id INT AUTO_INCREMENT NOT NULL, license_plate VARCHAR(255) NOT NULL, brand VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE messenger_messages (id BIGINT AUTO_INCREMENT NOT NULL, body LONGTEXT NOT NULL, headers LONGTEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', available_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', delivered_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_75EA56E0FB7336F0 (queue_name), INDEX IDX_75EA56E0E3BD61CE (available_at), INDEX IDX_75EA56E016BA31DB (delivered_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE fault'); + $this->addSql('DROP TABLE intervention'); + $this->addSql('DROP TABLE skill'); + $this->addSql('DROP TABLE stock'); + $this->addSql('DROP TABLE `user`'); + $this->addSql('DROP TABLE vehicle'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 3a2f4d1..0be20f0 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -5,16 +5,21 @@ namespace App\Entity; use App\Repository\UserRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; +use Symfony\Component\Security\Core\User\UserInterface; #[ORM\Entity(repositoryClass: UserRepository::class)] -#[ORM\Table(name: '`user`')] -class User +#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])] +class User implements UserInterface, PasswordAuthenticatedUserInterface { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; + #[ORM\Column(length: 180)] + private ?string $email = null; + #[ORM\Column(length: 255)] private ?string $FirstName = null; @@ -29,84 +34,154 @@ class User #[ORM\Column(length: 255)] private ?string $Phone = null; + /** + * @var list The user roles + */ + #[ORM\Column] + private array $roles = []; - #[ORM\Column(length: 255)] - private ?string $Type = null; + /** + * @var string The hashed password + */ + #[ORM\Column] + private ?string $password = null; public function getId(): ?int { return $this->id; } - public function getFirstName(): ?string - { - return $this->FirstName; - } - - public function setFirstName(string $FirstName): static - { - $this->FirstName = $FirstName; - - return $this; - } - - public function getLastName(): ?string - { - return $this->LastName; - } - - public function setLastName(string $LastName): static - { - $this->LastName = $LastName; - - return $this; - } - + /** + * @return \DateTimeInterface|null + */ public function getBirthDate(): ?\DateTimeInterface { return $this->BirthDate; } - public function setBirthDate(\DateTimeInterface $BirthDate): static + /** + * @param \DateTimeInterface|null $BirthDate + */ + public function setBirthDate(?\DateTimeInterface $BirthDate): void { $this->BirthDate = $BirthDate; - - return $this; } - public function getEmail(): ?string + /** + * @return string|null + */ + public function getLastName(): ?string { - return $this->Email; + return $this->LastName; } - public function setEmail(string $Email): static + /** + * @param string|null $LastName + */ + public function setLastName(?string $LastName): void { - $this->Email = $Email; - - return $this; + $this->LastName = $LastName; } + /** + * @return string|null + */ + public function getFirstName(): ?string + { + return $this->FirstName; + } + + /** + * @param string|null $FirstName + */ + public function setFirstName(?string $FirstName): void + { + $this->FirstName = $FirstName; + } + + /** + * @return string|null + */ public function getPhone(): ?string { return $this->Phone; } - public function setPhone(string $Phone): static + /** + * @param string|null $Phone + */ + public function setPhone(?string $Phone): void { $this->Phone = $Phone; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; return $this; } - public function getType(): ?string + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUserIdentifier(): string { - return $this->Type; + return (string) $this->email; } - public function setType(string $Type): static + /** + * @see UserInterface + * + * @return list + */ + public function getRoles(): array { - $this->Type = $Type; + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + /** + * @param list $roles + */ + public function setRoles(array $roles): static + { + $this->roles = $roles; return $this; } + + /** + * @see PasswordAuthenticatedUserInterface + */ + public function getPassword(): ?string + { + return $this->password; + } + + public function setPassword(string $password): static + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function eraseCredentials(): void + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } } diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index b29153b..4f2804e 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -5,17 +5,34 @@ namespace App\Repository; use App\Entity\User; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; +use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; /** * @extends ServiceEntityRepository */ -class UserRepository extends ServiceEntityRepository +class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, User::class); } + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); + } + + $user->setPassword($newHashedPassword); + $this->getEntityManager()->persist($user); + $this->getEntityManager()->flush(); + } + // /** // * @return User[] Returns an array of User objects // */ From 941cb2d04f917a7c99f5f43380090b738f9f9645 Mon Sep 17 00:00:00 2001 From: Maxiser Date: Thu, 28 Nov 2024 14:04:28 +0100 Subject: [PATCH 4/4] 2 --- .idea/workspace.xml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6152663..f85878b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -165,27 +165,27 @@