src/Entity/User.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Validator\Constraints\Json;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[UniqueEntity(fields: ['user_email'], message'Il existe déjà un compte avec cette adresse email.')]
  14. class User implements PasswordAuthenticatedUserInterfaceUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length255)]
  21.     #[Assert\NotBlank(message'Veuillez renseigner votre prénom.')]
  22.     #[Assert\Type(type'string'message'Le prénom doit être une chaîne de caractères.')]
  23.     private ?string $user_name null;
  24.     #[ORM\Column(length255)]
  25.     #[Assert\NotBlank(message'Veuillez renseigner votre nom.')]
  26.     #[Assert\Type(type'string'message'Le nom doit être une chaîne de caractères.')]
  27.     private ?string $user_surname null;
  28.     #[ORM\Column(length255uniquetrue)]
  29.     #[Assert\NotBlank(message'Veuillez renseigner une adresse email.')]
  30.     #[Assert\Email(message'Veuillez renseigner une adresse email valide.')]
  31.     private ?string $user_email null;
  32.     #[ORM\Column(length255)]
  33.     #[Assert\NotBlank(message'Veuillez renseigner un mot de passe.')]
  34.     #[Assert\Length(
  35.         min8,
  36.         max32,
  37.         minMessage'Votre mot de passe doit contenir au moins {{ limit }} caractères.',
  38.         maxMessage'Votre mot de passe ne peut pas faire plus de {{ limit }} caractères.')]
  39.     #[Assert\Regex(
  40.         pattern'/^(?=.*[0-9]).*$/',
  41.         message"Votre mot de passe doit contenir au moins un chiffre."
  42.     )]
  43.     #[Assert\Regex(
  44.         pattern'/^(?=.*[A-Z]).*$/',
  45.         message"Votre mot de passe doit contenir au moins une lettre majuscule."
  46.     )]
  47.     private ?string $user_password null;
  48.     #[ORM\OneToMany(mappedBy'order_user'targetEntityOrder::class)]
  49.     private Collection $orders;
  50.     #[ORM\Column]
  51.     private array $user_roles = ['ROLE_USER'];
  52.     private ?string $confirm_password null;
  53.     private ?string $confirm_email null;
  54.     public function __construct()
  55.     {
  56.         $this->orders = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getUserName(): ?string
  63.     {
  64.         return $this->user_name;
  65.     }
  66.     public function setUserName(string $user_name): self
  67.     {
  68.         $this->user_name $user_name;
  69.         return $this;
  70.     }
  71.     public function getUserSurname(): ?string
  72.     {
  73.         return $this->user_surname;
  74.     }
  75.     public function setUserSurname(string $user_surname): self
  76.     {
  77.         $this->user_surname $user_surname;
  78.         return $this;
  79.     }
  80.     public function getUserEmail(): ?string
  81.     {
  82.         return $this->user_email;
  83.     }
  84.     public function setUserEmail(string $user_email): self
  85.     {
  86.         $this->user_email $user_email;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return string|null
  91.      */
  92.     public function getUserPassword(): ?string
  93.     {
  94.         return $this->user_password;
  95.     }
  96.     /**
  97.      * @param string|null $user_password
  98.      */
  99.     public function setUserPassword(?string $user_password): void
  100.     {
  101.         $this->user_password $user_password;
  102.     }
  103.     public function getPassword(): ?string
  104.     {
  105.         return $this->user_password;
  106.     }
  107.     public function setPassword(string $user_password): self
  108.     {
  109.         $this->user_password $user_password;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, Order>
  114.      */
  115.     public function getOrders(): Collection
  116.     {
  117.         return $this->orders;
  118.     }
  119.     public function addOrder(Order $order): self
  120.     {
  121.         if (!$this->orders->contains($order)) {
  122.             $this->orders->add($order);
  123.             $order->setOrderUser($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeOrder(Order $order): self
  128.     {
  129.         if ($this->orders->removeElement($order)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($order->getOrderUser() === $this) {
  132.                 $order->setOrderUser(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getConfirmPassword(): ?string
  138.     {
  139.         return $this->confirm_password;
  140.     }
  141.     public function setConfirmPassword(string $confirm_password): self
  142.     {
  143.         $this->confirm_password $confirm_password;
  144.         return $this;
  145.     }
  146.     public function getConfirmEmail(): ?string
  147.     {
  148.         return $this->confirm_email;
  149.     }
  150.     public function setConfirmEmail(string $confirm_email): self
  151.     {
  152.         $this->confirm_email $confirm_email;
  153.         return $this;
  154.     }
  155.     public function getRoles(): array
  156.     {
  157.         $roles $this->user_roles;
  158.         // guarantee every user at least has ROLE_USER
  159.         $roles[] = 'ROLE_USER';
  160.         return array_unique($roles);
  161.     }
  162.     public function setRoles(array $roles): self
  163.     {
  164.         $this->user_roles $roles;
  165.         return $this;
  166.     }
  167.     public function eraseCredentials()
  168.     {
  169.         // TODO: Implement eraseCredentials() method.
  170.     }
  171.     public function getUserIdentifier(): string
  172.     {
  173.         return (string) $this->user_email;
  174.     }
  175.     public function getUserRoles(): array
  176.     {
  177.         return $this->user_roles;
  178.     }
  179.     public function setUserRoles(array $user_roles): self
  180.     {
  181.         $this->user_roles $user_roles;
  182.         return $this;
  183.     }
  184.     public function __toString(): string
  185.     {
  186.         return $this->user_name ' ' $this->user_surname;
  187.     }
  188. }