You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 line
3.2KB

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8. * @ORM\Entity(repositoryClass=UserRepository::class)
  9. * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  10. */
  11. class User implements UserInterface
  12. {
  13. /**
  14. * @ORM\Id
  15. * @ORM\GeneratedValue
  16. * @ORM\Column(type="integer")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=180, unique=true)
  21. */
  22. private $email;
  23. /**
  24. * @ORM\Column(type="json")
  25. */
  26. private $roles = [];
  27. /**
  28. * @var string The hashed password
  29. * @ORM\Column(type="string")
  30. */
  31. private $password;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. */
  35. private $lastname;
  36. /**
  37. * @ORM\Column(type="string", length=255, nullable=true)
  38. */
  39. private $firstname;
  40. /**
  41. * @ORM\Column(type="boolean")
  42. */
  43. private $isVerified = false;
  44. public function getId(): ?int
  45. {
  46. return $this->id;
  47. }
  48. public function getEmail(): ?string
  49. {
  50. return $this->email;
  51. }
  52. public function setEmail(string $email): self
  53. {
  54. $this->email = $email;
  55. return $this;
  56. }
  57. /**
  58. * A visual identifier that represents this user.
  59. *
  60. * @see UserInterface
  61. */
  62. public function getUsername(): string
  63. {
  64. return (string) $this->email;
  65. }
  66. /**
  67. * @see UserInterface
  68. */
  69. public function getRoles(): array
  70. {
  71. $roles = $this->roles;
  72. // guarantee every user at least has ROLE_USER
  73. $roles[] = 'ROLE_USER';
  74. return array_unique($roles);
  75. }
  76. public function setRoles(array $roles): self
  77. {
  78. $this->roles = $roles;
  79. return $this;
  80. }
  81. /**
  82. * @see UserInterface
  83. */
  84. public function getPassword(): string
  85. {
  86. return (string) $this->password;
  87. }
  88. public function setPassword(string $password): self
  89. {
  90. $this->password = $password;
  91. return $this;
  92. }
  93. /**
  94. * @see UserInterface
  95. */
  96. public function getSalt()
  97. {
  98. // not needed when using the "bcrypt" algorithm in security.yaml
  99. }
  100. /**
  101. * @see UserInterface
  102. */
  103. public function eraseCredentials()
  104. {
  105. // If you store any temporary, sensitive data on the user, clear it here
  106. // $this->plainPassword = null;
  107. }
  108. public function getLastname(): ?string
  109. {
  110. return $this->lastname;
  111. }
  112. public function setLastname(?string $lastname): self
  113. {
  114. $this->lastname = $lastname;
  115. return $this;
  116. }
  117. public function getFirstname(): ?string
  118. {
  119. return $this->firstname;
  120. }
  121. public function setFirstname(?string $firstname): self
  122. {
  123. $this->firstname = $firstname;
  124. return $this;
  125. }
  126. public function isVerified(): bool
  127. {
  128. return $this->isVerified;
  129. }
  130. public function setIsVerified(bool $isVerified): self
  131. {
  132. $this->isVerified = $isVerified;
  133. return $this;
  134. }
  135. }