src/Entity/User.php line 15

Open in your IDE?
  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\Table(name="users")
  9. * @ORM\Entity(repositoryClass=UserRepository::class)
  10. * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  11. */
  12. class User implements UserInterface
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(name="username", type="string", length=180, unique=true)
  22. */
  23. private $username;
  24. /**
  25. * @ORM\Column(type="string", length=180, unique=true)
  26. */
  27. private $email;
  28. /**
  29. * @ORM\Column(type="json")
  30. */
  31. private $roles = [];
  32. /**
  33. * @var string The hashed password
  34. * @ORM\Column(type="string")
  35. */
  36. private $password;
  37. /**
  38. * @ORM\Column(name="last_login", type="datetime")
  39. */
  40. private $lastLogin = false;
  41. /**
  42. * @ORM\Column(type="boolean")
  43. */
  44. private $isVerified = false;
  45. /**
  46. * @ORM\Column(type="boolean")
  47. */
  48. private $enabled= false;
  49. public function getId(): ?int
  50. {
  51. return $this->id;
  52. }
  53. public function getEmail(): ?string
  54. {
  55. return $this->email;
  56. }
  57. public function setEmail(string $email): self
  58. {
  59. $this->email = $email;
  60. return $this;
  61. }
  62. public function getUsername() {
  63. return $this->username;
  64. }
  65. public function setUsername($username): void {
  66. $this->username = $username;
  67. }
  68. /**
  69. * @see UserInterface
  70. */
  71. public function getRoles(): array
  72. {
  73. $roles = $this->roles;
  74. // guarantee every user at least has ROLE_USER
  75. $roles[] = 'ROLE_USER';
  76. return array_unique($roles);
  77. }
  78. public function setRoles(array $roles): self
  79. {
  80. $this->roles = $roles;
  81. return $this;
  82. }
  83. /**
  84. * @see UserInterface
  85. */
  86. public function getPassword(): string
  87. {
  88. return $this->password;
  89. }
  90. public function setPassword(string $password): self
  91. {
  92. $this->password = $password;
  93. return $this;
  94. }
  95. /**
  96. * Returning a salt is only needed, if you are not using a modern
  97. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  98. *
  99. * @see UserInterface
  100. */
  101. public function getSalt(): ?string
  102. {
  103. return null;
  104. }
  105. /**
  106. * @see UserInterface
  107. */
  108. public function eraseCredentials()
  109. {
  110. // If you store any temporary, sensitive data on the user, clear it here
  111. // $this->plainPassword = null;
  112. }
  113. public function isVerified(): bool
  114. {
  115. return $this->isVerified;
  116. }
  117. public function setIsVerified(bool $isVerified): self
  118. {
  119. $this->isVerified = $isVerified;
  120. return $this;
  121. }
  122. public function getLastLogin() {
  123. return $this->lastLogin;
  124. }
  125. public function setLastLogin($lastLogin): void {
  126. $this->lastLogin = $lastLogin;
  127. }
  128. public function getEnabled() {
  129. return $this->enabled;
  130. }
  131. public function setEnabled($enabled): void {
  132. $this->enabled = $enabled;
  133. }
  134. }