src/Domain/Entity/User.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace App\Domain\Entity;
  4. use App\Validators\UniqueUserDTO;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Serializable;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * Class User.
  11.  *
  12.  * @ORM\Entity(repositoryClass="App\Domain\Repository\UserRepository")
  13.  * @ORM\Table(name="user_tracol")
  14.  * @UniqueUserDTO()
  15.  */
  16. class User extends AbstractEntity implements UserInterfaceSerializable
  17. {
  18.     /** @var string
  19.      *
  20.      * @ORM\Column(type="string")
  21.      * @Assert\NotBlank(message="Veuillez renseigner les champs vides")
  22.      * @Assert\Email()
  23.      */
  24.     public ?string $email null;
  25.     /** @var string
  26.      *
  27.      * @ORM\Column(type="string")
  28.      * @Assert\NotBlank(message="Veuillez renseigner les champs vides")
  29.      */
  30.     public ?string $username null;
  31.     /** @var string
  32.      *
  33.      * @ORM\Column(type="string")
  34.      * @Assert\NotBlank(message="Veuillez renseigner les champs vides")
  35.      */
  36.     public string $name;
  37.     /** @var string
  38.      *
  39.      * @ORM\Column(type="string")
  40.      * @Assert\NotBlank(message="Veuillez renseigner les champs vides")
  41.      */
  42.     protected string $lastname;
  43.     /** @var string
  44.      *
  45.      * @ORM\Column(type="string")
  46.      */
  47.     protected string $password;
  48.     /** @var array
  49.      *
  50.      * @ORM\Column(type="array")
  51.      */
  52.     protected array $role;
  53.     /**
  54.      * @var string|null
  55.      *
  56.      * @ORM\Column(type="string", nullable=true)
  57.      */
  58.     protected ?string $token;
  59.     /**
  60.      * @ORM\Column(type="boolean")
  61.      */
  62.     private bool $isVerified false;
  63.     public function __construct() {
  64.         $this->role[] = 'ROLE_USER';
  65.         $this->isVerified false;
  66.         $this->createdAt time();
  67.         parent::__construct();
  68.     }
  69.     /**
  70.      * @return string
  71.      */
  72.     public function getEmail(): string
  73.     {
  74.         return $this->email;
  75.     }
  76.     public function setEmail($email): User
  77.     {
  78.         $this->email $email;
  79.         return $this;
  80.     }
  81.     public function getUsername(): ?string
  82.     {
  83.         return $this->username;
  84.     }
  85.     public function setUsername($username): ?User
  86.     {
  87.         $this->username $username;
  88.         return $this;
  89.     }
  90.     public function getName(): string
  91.     {
  92.         return $this->name;
  93.     }
  94.     public function setName($name): User
  95.     {
  96.         $this->name $name;
  97.         return $this;
  98.     }
  99.     public function getLastname(): string
  100.     {
  101.         return $this->lastname;
  102.     }
  103.     public function setLastname($lastname): User
  104.     {
  105.         $this->lastname $lastname;
  106.         return $this;
  107.     }
  108.     public function getPassword(): string
  109.     {
  110.         return $this->password;
  111.     }
  112.     public function setPassword($plainPassword): User
  113.     {
  114.         $this->password $plainPassword;
  115.         return $this;
  116.     }
  117.     public function getToken(): ?string
  118.     {
  119.         return $this->token;
  120.     }
  121.     public function updateToken(?string $token): self
  122.     {
  123.         $this->token $token;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return array
  128.      */
  129.     public function getRoles()
  130.     {
  131.         return $this->role;
  132.     }
  133.     /**
  134.      * @return array
  135.      */
  136.     public function getRole()
  137.     {
  138.         return $this->role;
  139.     }
  140.     /**
  141.      * @param $newRole
  142.      */
  143.     public function changeRole(array $newRole): void
  144.     {
  145.         $this->role $newRole;
  146.     }
  147.     /**
  148.      * @param string $roleAdd
  149.      */
  150.     public function addRole(string $roleAdd): void
  151.     {
  152.         $this->role[] = $roleAdd;
  153.     }
  154.     public function isVerified(): bool
  155.     {
  156.         return $this->isVerified;
  157.     }
  158.     public function setIsVerified(bool $isVerified): self
  159.     {
  160.         $this->isVerified $isVerified;
  161.         return $this;
  162.     }
  163.     public function passwordReset(string  $newPassword )
  164.     {
  165.         $this->password $newPassword;
  166.         $this->passwordResetToken null;
  167.     }
  168.     public function updatePassword(string $newpassword)
  169.     {
  170.         $this->password $newpassword;
  171.         $this->passwordResetToken null;
  172.     }
  173.     public function getSalt(): ?string
  174.     {
  175.         return $this->password;
  176.     }
  177.     public function eraseCredentials()
  178.     {
  179.     }
  180.     public function serialize(): string
  181.     {
  182.         return serialize([
  183.             $this->id,
  184.             $this->username,
  185.             $this->email,
  186.             $this->password,
  187.             $this->role
  188.         ]);
  189.     }
  190.     function unserialize($serialized)
  191.     {
  192.         list(
  193.             $this->id,
  194.             $this->username,
  195.             $this->email,
  196.             $this->password,
  197.             $this->role
  198.             ) = unserialize($serialized);
  199.     }
  200. }