diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..9156fa5 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,34 @@ + + + +<<<<<<< HEAD + + 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 +======= + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://172.20.96.1:5432/chauffageproj + $ProjectFileDir$ + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://172.20.96.1:5432/chauffageproj +>>>>>>> ee236ff74aaac1882a825817d5ce8f692d3bdd0f + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d042e16..34b9e45 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,10 @@ - + + + $PROJECT_DIR$/composer.json - + + + - + @@ -163,19 +167,40 @@ - { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", +<<<<<<< HEAD + "git-widget-placeholder": "develop", + "last_opened_file_path": "E:/BTS/PhpStorm/centre_fitness", +======= + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "develop", + "last_opened_file_path": "/home/ragueneaul@stsio.lan/Documents/DecoMaison_Lucas_Ragueneau", +>>>>>>> ee236ff74aaac1882a825817d5ce8f692d3bdd0f + "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", +<<<<<<< HEAD + "php.add.doc.comment.for.fields.panel.add.php.doc.for.all.properties": "true", + "settings.editor.selected.configurable": "inlay.hints", +======= +>>>>>>> ee236ff74aaac1882a825817d5ce8f692d3bdd0f + "vue.rearranger.settings.migration": "true" + }, + "keyToStringList": { + "DatabaseDriversLRU": [ +<<<<<<< HEAD + "postgresql", + "mysql" +======= + "postgresql" +>>>>>>> ee236ff74aaac1882a825817d5ce8f692d3bdd0f + ] } -}]]> +} @@ -190,8 +215,13 @@ - @@ -206,6 +236,13 @@ +<<<<<<< HEAD + +======= + + + +>>>>>>> ee236ff74aaac1882a825817d5ce8f692d3bdd0f 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/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/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/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/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/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/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 // */ 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..e48b70b --- /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.Email }} + {{ user.Phone }} + {{ user.Type }} + {% endfor %} +{% endblock %} \ No newline at end of file