src/Entity/User.php line 27

  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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Scheb\TwoFactorBundle\Model\Totp\TotpConfiguration;
  14. use Scheb\TwoFactorBundle\Model\Totp\TotpConfigurationInterface;
  15. use Scheb\TwoFactorBundle\Model\Totp\TwoFactorInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[ORM\Entity(repositoryClass: UserRepository::class)]
  18. #[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
  19. #[Vich\Uploadable]
  20. class User implements UserInterface, PasswordAuthenticatedUserInterface
  21. {
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     private ?int $id = null;
  26.     #[ORM\Column(length: 180, unique: true)]
  27.     private ?string $email = null;
  28.     #[ORM\Column]
  29.     private array $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      */
  33.     #[ORM\Column(nullable: true)]
  34.     #[Assert\Length(min: 8, minMessage: "Le mot de passe doit faire au moins 8 caractères")]
  35.     private ?string $password = null;
  36.     #[ORM\Column(length: 100)]
  37.     private ?string $firstname = null;
  38.     #[ORM\Column(length: 100, nullable: true)]
  39.     private ?string $lastname = null;
  40.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  41.     private ?\DateTimeInterface $CreatedAt = null;
  42.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  43.     private ?\DateTimeInterface $UpdatedAt = null;
  44.     #[ORM\Column(nullable: true)]
  45.     private ?bool $Enable = null;
  46.     #[ORM\Column(length: 5, nullable: true)]
  47.     private ?string $language = null;
  48.     #[ORM\Column(nullable: true)]
  49.     private ?bool $isVerified = null;
  50.     #[ORM\ManyToOne(inversedBy: 'users')]
  51.     private ?LawOffice $LawOffice = null;
  52.     // NOTE: This is not a mapped field of entity metadata, just a simple property.
  53.     #[Vich\UploadableField(mapping: 'user_avatar', fileNameProperty: 'avatarName', size: 'avatarSize')]
  54.     private ?File $avatarFile = null;
  55.     #[ORM\Column(nullable: true)]
  56.     private ?string $avatarName = null;
  57.     #[ORM\Column(nullable: true)]
  58.     private ?int $avatarSize = null;
  59.     #[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Client::class)]
  60.     private Collection $clients;
  61.     #[ORM\OneToMany(mappedBy: 'CreatedBy', targetEntity: TheCase::class)]
  62.     private Collection $theCases;
  63.     #[ORM\OneToMany(mappedBy: 'CreatedBy', targetEntity: Files::class)]
  64.     private Collection $files;
  65.     #[ORM\Column(nullable: true)]
  66.     private ?string $totpSecret;
  67.     public function __construct()
  68.     {
  69.         $this->clients = new ArrayCollection();
  70.         $this->theCases = new ArrayCollection();
  71.         $this->files = new ArrayCollection();
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getEmail(): ?string
  78.     {
  79.         return $this->email;
  80.     }
  81.     public function setEmail(string $email): self
  82.     {
  83.         $this->email = $email;
  84.         return $this;
  85.     }
  86.     /**
  87.      * A visual identifier that represents this user.
  88.      *
  89.      * @see UserInterface
  90.      */
  91.     public function getUserIdentifier(): string
  92.     {
  93.         return (string) $this->email;
  94.     }
  95.     /**
  96.      * @see UserInterface
  97.      */
  98.     public function getRoles(): array
  99.     {
  100.         $roles = $this->roles;
  101.         // guarantee every user at least has ROLE_USER
  102.         $roles[] = 'ROLE_USER';
  103.         return array_unique($roles);
  104.     }
  105.     public function setRoles(array $roles): self
  106.     {
  107.         $this->roles = $roles;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @see PasswordAuthenticatedUserInterface
  112.      */
  113.     public function getPassword(): string
  114.     {
  115.         return $this->password;
  116.     }
  117.     public function setPassword(string $password): self
  118.     {
  119.         $this->password = $password;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @see UserInterface
  124.      */
  125.     public function eraseCredentials()
  126.     {
  127.         // If you store any temporary, sensitive data on the user, clear it here
  128.         // $this->plainPassword = null;
  129.     }
  130.     public function getFirstname(): ?string
  131.     {
  132.         return $this->firstname;
  133.     }
  134.     public function setFirstname(string $firstname): self
  135.     {
  136.         $this->firstname = $firstname;
  137.         return $this;
  138.     }
  139.     public function getLastname(): ?string
  140.     {
  141.         return $this->lastname;
  142.     }
  143.     public function setLastname(?string $lastname): self
  144.     {
  145.         $this->lastname = $lastname;
  146.         return $this;
  147.     }
  148.     public function getCreatedAt(): ?\DateTimeInterface
  149.     {
  150.         return $this->CreatedAt;
  151.     }
  152.     public function setCreatedAt(?\DateTimeInterface $CreatedAt): self
  153.     {
  154.         $this->CreatedAt = $CreatedAt;
  155.         return $this;
  156.     }
  157.     public function getUpdatedAt(): ?\DateTimeInterface
  158.     {
  159.         return $this->UpdatedAt;
  160.     }
  161.     public function setUpdatedAt(?\DateTimeInterface $UpdatedAt): self
  162.     {
  163.         $this->UpdatedAt = $UpdatedAt;
  164.         return $this;
  165.     }
  166.     public function isEnable(): ?bool
  167.     {
  168.         return $this->Enable;
  169.     }
  170.     public function setEnable(?bool $Enable): self
  171.     {
  172.         $this->Enable = $Enable;
  173.         return $this;
  174.     }
  175.     public function getLanguage(): ?string
  176.     {
  177.         return $this->language;
  178.     }
  179.     public function setLanguage(?string $language): self
  180.     {
  181.         $this->language = $language;
  182.         return $this;
  183.     }
  184.     public function isIsVerified(): ?bool
  185.     {
  186.         return $this->isVerified;
  187.     }
  188.     public function setIsVerified(?bool $isVerified): self
  189.     {
  190.         $this->isVerified = $isVerified;
  191.         return $this;
  192.     }
  193.     public function isVerified(): bool
  194.     {
  195.         return $this->isVerified;
  196.     }
  197.     public function getLawOffice(): ?LawOffice
  198.     {
  199.         return $this->LawOffice;
  200.     }
  201.     public function setLawOffice(?LawOffice $LawOffice): self
  202.     {
  203.         $this->LawOffice = $LawOffice;
  204.         return $this;
  205.     }
  206.     /**
  207.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  208.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  209.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  210.      * must be able to accept an instance of 'File' as the bundle will inject one here
  211.      * during Doctrine hydration.
  212.      *
  213.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $avatarFile
  214.      */
  215.     public function setAvatarFile(?File $avatarFile = null): void
  216.     {
  217.         $this->avatarFile = $avatarFile;
  218.         if (null !== $avatarFile) {
  219.             // It is required that at least one field changes if you are using doctrine
  220.             // otherwise the event listeners won't be called and the file is lost
  221.             $this->updatedAt = new \DateTimeImmutable();
  222.         }
  223.     }
  224.     public function getAvatarFile(): ?File
  225.     {
  226.         return $this->avatarFile;
  227.     }
  228.     public function setAvatarName(?string $avatarName): void
  229.     {
  230.         $this->avatarName = $avatarName;
  231.     }
  232.     public function getAvatarName(): ?string
  233.     {
  234.         return $this->avatarName;
  235.     }
  236.     public function setAvatarSize(?int $avatarSize): void
  237.     {
  238.         $this->avatarSize = $avatarSize;
  239.     }
  240.     public function getAvatarSize(): ?int
  241.     {
  242.         return $this->avatarSize;
  243.     }
  244.     /**
  245.      * @return Collection<int, Client>
  246.      */
  247.     public function getClients(): Collection
  248.     {
  249.         return $this->clients;
  250.     }
  251.     public function addClient(Client $client): self
  252.     {
  253.         if (!$this->clients->contains($client)) {
  254.             $this->clients->add($client);
  255.             $client->setCreatedBy($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeClient(Client $client): self
  260.     {
  261.         if ($this->clients->removeElement($client)) {
  262.             // set the owning side to null (unless already changed)
  263.             if ($client->getCreatedBy() === $this) {
  264.                 $client->setCreatedBy(null);
  265.             }
  266.         }
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, TheCase>
  271.      */
  272.     public function getTheCases(): Collection
  273.     {
  274.         return $this->theCases;
  275.     }
  276.     public function addTheCase(TheCase $theCase): self
  277.     {
  278.         if (!$this->theCases->contains($theCase)) {
  279.             $this->theCases->add($theCase);
  280.             $theCase->setCreatedBy($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeTheCase(TheCase $theCase): self
  285.     {
  286.         if ($this->theCases->removeElement($theCase)) {
  287.             // set the owning side to null (unless already changed)
  288.             if ($theCase->getCreatedBy() === $this) {
  289.                 $theCase->setCreatedBy(null);
  290.             }
  291.         }
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection<int, Files>
  296.      */
  297.     public function getFiles(): Collection
  298.     {
  299.         return $this->files;
  300.     }
  301.     public function addFile(Files $file): self
  302.     {
  303.         if (!$this->files->contains($file)) {
  304.             $this->files->add($file);
  305.             $file->setCreatedBy($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeFile(Files $file): self
  310.     {
  311.         if ($this->files->removeElement($file)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($file->getCreatedBy() === $this) {
  314.                 $file->setCreatedBy(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     public function isTotpAuthenticationEnabled(): bool
  320.     {
  321.         return $this->totpSecret ? true : false;
  322.     }
  323.     public function getTotpAuthenticationUsername(): string
  324.     {
  325.         return $this->email;
  326.     }
  327.     public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface
  328.     {
  329.         // You could persist the other configuration options in the user entity to make it individual per user.
  330.         return new TotpConfiguration($this->totpSecret, TotpConfiguration::ALGORITHM_SHA1, 20, 8);
  331.     }
  332. }