src/Entity/ApiUser.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ApiUserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8. * @ORM\Entity(repositoryClass=ApiUserRepository::class)
  9. */
  10. class ApiUser implements UserInterface, PasswordAuthenticatedUserInterface
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=180, unique=true)
  20. */
  21. private $username;
  22. /**
  23. * @ORM\Column(type="json")
  24. */
  25. private $roles = [];
  26. /**
  27. * @var string The hashed password
  28. * @ORM\Column(type="string")
  29. */
  30. private $password;
  31. /**
  32. * @ORM\Column(type="text", nullable=true)
  33. */
  34. private $token;
  35. /**
  36. * @ORM\Column(type="datetime", nullable=true)
  37. */
  38. private $lastLoginAt;
  39. public function getId(): ?int
  40. {
  41. return $this->id;
  42. }
  43. /**
  44. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  45. */
  46. public function getUsername(): string
  47. {
  48. return (string) $this->username;
  49. }
  50. public function setUsername(string $username): self
  51. {
  52. $this->username = $username;
  53. return $this;
  54. }
  55. /**
  56. * A visual identifier that represents this user.
  57. *
  58. * @see UserInterface
  59. */
  60. public function getUserIdentifier(): string
  61. {
  62. return (string) $this->username;
  63. }
  64. /**
  65. * @see UserInterface
  66. */
  67. public function getRoles(): array
  68. {
  69. $roles = $this->roles;
  70. // guarantee every user at least has ROLE_USER
  71. $roles[] = 'ROLE_USER';
  72. return array_unique($roles);
  73. }
  74. public function setRoles(array $roles): self
  75. {
  76. $this->roles = $roles;
  77. return $this;
  78. }
  79. /**
  80. * @see PasswordAuthenticatedUserInterface
  81. */
  82. public function getPassword(): string
  83. {
  84. return $this->password;
  85. }
  86. public function setPassword(string $password): self
  87. {
  88. $this->password = $password;
  89. return $this;
  90. }
  91. /**
  92. * Returning a salt is only needed, if you are not using a modern
  93. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  94. *
  95. * @see UserInterface
  96. */
  97. public function getSalt(): ?string
  98. {
  99. return null;
  100. }
  101. /**
  102. * @see UserInterface
  103. */
  104. public function eraseCredentials()
  105. {
  106. // If you store any temporary, sensitive data on the user, clear it here
  107. // $this->plainPassword = null;
  108. }
  109. public function getToken(): ?string
  110. {
  111. return $this->token;
  112. }
  113. public function setToken(?string $token): self
  114. {
  115. $this->token = $token;
  116. return $this;
  117. }
  118. public function getLastLoginAt(): ?\DateTimeInterface
  119. {
  120. return $this->lastLoginAt;
  121. }
  122. public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self
  123. {
  124. $this->lastLoginAt = $lastLoginAt;
  125. return $this;
  126. }
  127. }