src/Entity/SpecialUser.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. #[ORM\Entity(repositoryClass: 'SpecialUserRepository')]
  7. #[ORM\Table(name: 'SpecialUsers')]
  8. class SpecialUser implements PasswordAuthenticatedUserInterface
  9. {
  10. public $active;
  11. #[ORM\Column(type: 'integer')]
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue(strategy: 'AUTO')]
  14. private readonly int $id;
  15. #[Assert\NotBlank(message: 'The username should not be blank')]
  16. #[ORM\Column(type: 'string', length: 25, unique: true)]
  17. private ?string $username = null;
  18. #[ORM\Column(type: 'string', length: 64)]
  19. private ?string $password = null;
  20. #[Assert\NotBlank(message: 'The email should not be blank')]
  21. #[Assert\Email]
  22. #[ORM\Column(type: 'string', length: 60, unique: true)]
  23. private ?string $email = null;
  24. #[ORM\Column(name: 'name', type: 'string', nullable: true)]
  25. private ?string $name = null;
  26. #[ORM\Column(name: 'is_active', type: 'boolean')]
  27. private bool $isActive = true;
  28. #[ORM\Column(type: 'array')]
  29. private ?array $roles = null;
  30. #[ORM\Column(name: 'emailresetkey', type: 'string', nullable: true)]
  31. private ?string $emailresetkey = null;
  32. #[Assert\Length(max: 4096)]
  33. private $plainPassword;
  34. public function __construct() {}
  35. public function getUsername()
  36. {
  37. return $this->username;
  38. }
  39. public function getSalt()
  40. {
  41. // you *may* need a real salt depending on your encoder
  42. // see section on salt below
  43. return null;
  44. }
  45. public function getPassword(): ?string
  46. {
  47. return $this->password;
  48. }
  49. public function eraseCredentials() {}
  50. /** @see \Serializable::serialize() */
  51. public function serialize()
  52. {
  53. return serialize([
  54. $this->id,
  55. $this->username,
  56. $this->password,
  57. $this->active,
  58. // see section on salt below
  59. // $this->salt,
  60. ]);
  61. }
  62. /** @see \Serializable::unserialize() */
  63. public function unserialize($serialized)
  64. {
  65. [$this->id, $this->username, $this->password, $this->isActive] = unserialize($serialized);
  66. }
  67. /**
  68. * Get id.
  69. *
  70. * @return int
  71. */
  72. public function getId()
  73. {
  74. return $this->id;
  75. }
  76. /**
  77. * Set username.
  78. *
  79. * @param string $username
  80. *
  81. * @return User
  82. */
  83. public function setUsername($username)
  84. {
  85. $this->username = $username;
  86. return $this;
  87. }
  88. /**
  89. * Set password.
  90. *
  91. * @param string $password
  92. *
  93. * @return User
  94. */
  95. public function setPassword($password)
  96. {
  97. $this->password = $password;
  98. return $this;
  99. }
  100. /**
  101. * Set email.
  102. *
  103. * @param string $email
  104. *
  105. * @return User
  106. */
  107. public function setEmail($email)
  108. {
  109. $this->email = $email;
  110. return $this;
  111. }
  112. /**
  113. * Get email.
  114. *
  115. * @return string
  116. */
  117. public function getEmail()
  118. {
  119. return $this->email;
  120. }
  121. /**
  122. * Set name.
  123. *
  124. * @param string $name
  125. *
  126. * @return User
  127. */
  128. public function setName($name)
  129. {
  130. $this->name = $name;
  131. return $this;
  132. }
  133. /**
  134. * Get name.
  135. *
  136. * @return string
  137. */
  138. public function getName()
  139. {
  140. return $this->name;
  141. }
  142. /**
  143. * Set isActive.
  144. *
  145. * @param bool $isActive
  146. *
  147. * @return User
  148. */
  149. public function setIsActive($isActive)
  150. {
  151. $this->isActive = $isActive;
  152. return $this;
  153. }
  154. /**
  155. * Get isActive.
  156. *
  157. * @return bool
  158. */
  159. public function getIsActive()
  160. {
  161. return $this->isActive;
  162. }
  163. public function isAccountNonExpired()
  164. {
  165. return true;
  166. }
  167. public function isAccountNonLocked()
  168. {
  169. return true;
  170. }
  171. public function isCredentialsNonExpired()
  172. {
  173. return true;
  174. }
  175. public function isEnabled()
  176. {
  177. return $this->isActive;
  178. }
  179. public function getRoles()
  180. {
  181. return $this->roles;
  182. }
  183. public function getPlainPassword()
  184. {
  185. return $this->plainPassword;
  186. }
  187. public function setPlainPassword($password)
  188. {
  189. $this->plainPassword = $password;
  190. }
  191. /**
  192. * Set roles.
  193. *
  194. * @param array $roles
  195. *
  196. * @return User
  197. */
  198. public function setRoles($roles)
  199. {
  200. $this->roles = $roles;
  201. return $this;
  202. }
  203. public function addRole($role)
  204. {
  205. $role = strtoupper((string) $role);
  206. if (!in_array($role, $this->roles, true)) {
  207. $this->roles[] = $role;
  208. }
  209. return $this;
  210. }
  211. /**
  212. * Set emailresetkey.
  213. *
  214. * @param string $emailresetkey
  215. *
  216. * @return User
  217. */
  218. public function setEmailresetkey($emailresetkey)
  219. {
  220. $this->emailresetkey = $emailresetkey;
  221. return $this;
  222. }
  223. /**
  224. * Get emailresetkey.
  225. *
  226. * @return string
  227. */
  228. public function getEmailresetkey()
  229. {
  230. return $this->emailresetkey;
  231. }
  232. public function getUserIdentifier()
  233. {
  234. return $this->username;
  235. }
  236. }