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_app")
  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.         parent::__construct();
  67.     }
  68.     /**
  69.      * @return string
  70.      */
  71.     public function getEmail(): string
  72.     {
  73.         return $this->email;
  74.     }
  75.     public function setEmail($email): User
  76.     {
  77.         $this->email $email;
  78.         return $this;
  79.     }
  80.     public function getUsername(): ?string
  81.     {
  82.         return $this->username;
  83.     }
  84.     public function setUsername($username): ?User
  85.     {
  86.         $this->username $username;
  87.         return $this;
  88.     }
  89.     public function getName(): string
  90.     {
  91.         return $this->name;
  92.     }
  93.     public function setName($name): User
  94.     {
  95.         $this->name $name;
  96.         return $this;
  97.     }
  98.     public function getLastname(): string
  99.     {
  100.         return $this->lastname;
  101.     }
  102.     public function setLastname($lastname): User
  103.     {
  104.         $this->lastname $lastname;
  105.         return $this;
  106.     }
  107.     public function getPassword(): string
  108.     {
  109.         return $this->password;
  110.     }
  111.     public function setPassword($plainPassword): User
  112.     {
  113.         $this->password $plainPassword;
  114.         return $this;
  115.     }
  116.     public function getToken(): ?string
  117.     {
  118.         return $this->token;
  119.     }
  120.     public function updateToken(?string $token): self
  121.     {
  122.         $this->token $token;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return array
  127.      */
  128.     public function getRoles()
  129.     {
  130.         return $this->role;
  131.     }
  132.     /**
  133.      * @return array
  134.      */
  135.     public function getRole()
  136.     {
  137.         return $this->role;
  138.     }
  139.     /**
  140.      * @param $newRole
  141.      */
  142.     public function changeRole(array $newRole): void
  143.     {
  144.         $this->role $newRole;
  145.     }
  146.     /**
  147.      * @param string $roleAdd
  148.      */
  149.     public function addRole(string $roleAdd): void
  150.     {
  151.         $this->role[] = $roleAdd;
  152.     }
  153.     public function isVerified(): bool
  154.     {
  155.         return $this->isVerified;
  156.     }
  157.     public function setIsVerified(bool $isVerified): self
  158.     {
  159.         $this->isVerified $isVerified;
  160.         return $this;
  161.     }
  162.     public function passwordReset(string  $newPassword )
  163.     {
  164.         $this->password $newPassword;
  165.         $this->passwordResetToken null;
  166.     }
  167.     public function updatePassword(string $newpassword)
  168.     {
  169.         $this->password $newpassword;
  170.         $this->passwordResetToken null;
  171.     }
  172.     public function getSalt(): ?string
  173.     {
  174.         return $this->password;
  175.     }
  176.     public function eraseCredentials()
  177.     {
  178.     }
  179.     public function serialize(): string
  180.     {
  181.         return serialize([
  182.             $this->id,
  183.             $this->username,
  184.             $this->email,
  185.             $this->password,
  186.             $this->role
  187.         ]);
  188.     }
  189.     public function getUserIdentifier(): string
  190.     {
  191.         return $this->username;
  192.     }
  193.     function unserialize($serialized)
  194.     {
  195.         list(
  196.             $this->id,
  197.             $this->username,
  198.             $this->email,
  199.             $this->password,
  200.             $this->role
  201.             ) = unserialize($serialized);
  202.     }
  203. }