src/Entity/User.php line 20

Open in your IDE?
  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\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\InheritanceType("JOINED")]
  11. #[ORM\DiscriminatorColumn(name"type"type"string")]
  12. #[ORM\DiscriminatorMap(["User" => User::class,"consultant" => Consultants::class, "entreprise" => Entreprises::class, "administrateur" => Administrateurs::class, "comerciaux" => Comerciaux::class])]
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. #[UniqueEntity(fields: ['email'], message'Ce mail appartient déjà à un compte')]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     private $id;
  21.     #[ORM\Column(type'string'length180uniquetrue)]
  22.     private $email;
  23.     #[ORM\Column(type'json')]
  24.     private $roles = [];
  25.     #[ORM\Column(type'string')]
  26.     private $password;
  27.     #[ORM\Column(type'boolean')]
  28.     private $isVerified false;
  29.     #[ORM\Column(type'string'length20)]
  30.     private $num;
  31.     #[ORM\Column(type'string'nullable:true)]
  32.     private ?string $confirmpassword;
  33.     // public function __serialize(): array
  34.     // {
  35.     //     return [
  36.     //         'email' => $this->email,
  37.     //         'password' => $this->password,
  38.     //     ];
  39.     // }
  40.     // public function __unserialize(array $data): void
  41.     // {
  42.     //     $this->email = $data['email'];
  43.     //     $this->password = $data['password'];
  44.     // }
  45.     public function __construct()
  46.     {
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getEmail(): ?string
  53.     {
  54.         return $this->email;
  55.     }
  56.     public function setEmail(string $email): self
  57.     {
  58.         $this->email $email;
  59.         return $this;
  60.     }
  61.     public function __serialize(): array
  62.     {
  63.         return [
  64.             'id' => $this->id,
  65.             'email' => $this->email,
  66.             'password' => $this->password,
  67.             'num' => $this->num// Inclure num
  68.         ];
  69.     }
  70.     public function __unserialize(array $data): void
  71.     {
  72.         $this->id $data['id'];
  73.         $this->email $data['email'];
  74.         $this->password $data['password'];
  75.         $this->num $data['num'] ?? null// Restaurer num
  76.     }
  77.     /**
  78.      * A visual identifier that represents this user.
  79.      *
  80.      * @see UserInterface
  81.      */
  82.     public function getUserIdentifier(): string
  83.     {
  84.         return (string) $this->email;
  85.     }
  86.     /**
  87.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  88.      */
  89.     public function getUsername(): string
  90.     {
  91.         return (string) $this->email;
  92.     }
  93.     /**
  94.      * @see UserInterface
  95.      */
  96.     public function getRoles(): array
  97.     {
  98.         $roles $this->roles;
  99.         // guarantee every user at least has ROLE_USER
  100.         $roles[] = 'ROLE_USER';
  101.         return array_unique($roles);
  102.     }
  103.     public function setRoles(array $roles): self
  104.     {
  105.         $this->roles $roles;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @see PasswordAuthenticatedUserInterface
  110.      */
  111.     public function getPassword(): string
  112.     {
  113.         return $this->password;
  114.     }
  115.     public function setPassword(string $password): self
  116.     {
  117.         $this->password $password;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Returning a salt is only needed, if you are not using a modern
  122.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  123.      *
  124.      * @see UserInterface
  125.      */
  126.     public function getSalt(): ?string
  127.     {
  128.         return null;
  129.     }
  130.     /**
  131.      * @see UserInterface
  132.      */
  133.     public function eraseCredentials()
  134.     {
  135.         // If you store any temporary, sensitive data on the user, clear it here
  136.         // $this->plainPassword = null;
  137.     }
  138.     public function isVerified(): bool
  139.     {
  140.         return $this->isVerified;
  141.     }
  142.     public function setIsVerified(bool $isVerified): self
  143.     {
  144.         $this->isVerified $isVerified;
  145.         return $this;
  146.     }
  147.     public function getNum(): ?string
  148.     {
  149.         return $this->num;
  150.     }
  151.     public function setNum(string $num): self
  152.     {
  153.         $this->num $num;
  154.         return $this;
  155.     }
  156.     public function getConfirmpassword(): ?string
  157.     {
  158.         return $this->confirmpassword;
  159.     }
  160.     public function setConfirmpassword(string $confirmpassword): static
  161.     {
  162.         $this->confirmpassword $confirmpassword;
  163.         return $this;
  164.     }
  165. }