src/Entity/User.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: parcel
  5. * Date: 9/20/18
  6. * Time: 4:03 PM
  7. */
  8. namespace App\Entity;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use JMS\Serializer\Annotation as Serializer;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. use Symfony\Component\Serializer\Annotation\Ignore;
  14. /**
  15. * @ORM\Entity
  16. * @ORM\Table(name="user",
  17. * uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"}),
  18. * @ORM\UniqueConstraint(name="person_id", columns={"person_id"}),
  19. * @ORM\UniqueConstraint(name="email", columns={"email"})})
  20. *
  21. */
  22. class User implements UserInterface, PasswordAuthenticatedUserInterface {
  23. /**
  24. * @ORM\Id
  25. * @ORM\GeneratedValue(strategy="IDENTITY")
  26. * @ORM\Column(type="integer")
  27. */
  28. private $id;
  29. /**
  30. * @ORM\Column(type="string", length=100)
  31. */
  32. private $username;
  33. /**
  34. * @Ignore
  35. * @Serializer\Exclude()
  36. * @ORM\Column(type="text")
  37. */
  38. private $password;
  39. private $plainPassword;
  40. /**
  41. * @Serializer\Type("DateTime<'d/m/Y'>")
  42. * @ORM\Column(type="datetime")
  43. */
  44. private $createdAt;
  45. /**
  46. * @var Person
  47. * @Serializer\Type("App\Entity\Person")
  48. * @ORM\ManyToOne(targetEntity="App\Entity\Person", cascade={"persist", "remove"})
  49. * @ORM\JoinColumns({
  50. * @ORM\JoinColumn(name="person_id", referencedColumnName="id")
  51. * })
  52. */
  53. private $person;
  54. /**
  55. * @Ignore
  56. * @ORM\Column(type="json")
  57. */
  58. private $roles;
  59. /**
  60. * @ORM\Column(type="string", length=45)
  61. */
  62. private $email;
  63. /**
  64. * @ORM\Column(type="boolean")
  65. */
  66. private $isActive;
  67. /**
  68. * Returns the roles granted to the user.
  69. *
  70. * <code>
  71. * public function getRoles()
  72. * {
  73. * return array('ROLE_USER');
  74. * }
  75. * </code>
  76. *
  77. * Alternatively, the roles might be stored on a ``roles`` property,
  78. * and populated in any number of different ways when the user object
  79. * is created.
  80. *
  81. * @return (Role|string)[] The user roles
  82. */
  83. public function getRoles()
  84. {
  85. // TODO: Implement getRoles() method.
  86. return $this->roles;
  87. }
  88. /**
  89. * Returns the password used to authenticate the user.
  90. *
  91. * This should be the encoded password. On authentication, a plain-text
  92. * password will be salted, encoded, and then compared to this value.
  93. *
  94. * @return string The password
  95. */
  96. public function getPassword() : ?string {
  97. // TODO: Implement getPassword() method.
  98. return $this->password;
  99. }
  100. /**
  101. * Returns the salt that was originally used to encode the password.
  102. *
  103. * This can return null if the password was not encoded using a salt.
  104. *
  105. * @return string|null The salt
  106. */
  107. public function getSalt()
  108. {
  109. // TODO: Implement getSalt() method.
  110. }
  111. /**
  112. * Returns the username used to authenticate the user.
  113. *
  114. * @return string The username
  115. */
  116. public function getUsername()
  117. {
  118. // TODO: Implement getUsername() method.
  119. return $this->username;
  120. }
  121. /**
  122. * Removes sensitive data from the user.
  123. *
  124. * This is important if, at any given point, sensitive information like
  125. * the plain-text password is stored on this object.
  126. */
  127. public function eraseCredentials()
  128. {
  129. // TODO: Implement eraseCredentials() method.
  130. $this->plainPassword = "";
  131. }
  132. /**
  133. * @return mixed
  134. */
  135. public function getId()
  136. {
  137. return $this->id;
  138. }
  139. /**
  140. * @param mixed $id
  141. */
  142. public function setId($id)
  143. {
  144. $this->id = $id;
  145. }
  146. /**
  147. * @return mixed
  148. */
  149. public function getPlainPassword()
  150. {
  151. return $this->plainPassword;
  152. }
  153. /**
  154. * @param mixed $plainPassword
  155. */
  156. public function setPlainPassword($plainPassword)
  157. {
  158. $this->plainPassword = $plainPassword;
  159. }
  160. /**
  161. * @return mixed
  162. */
  163. public function getCreatedAt(){
  164. return $this->createdAt;
  165. }
  166. /**
  167. * @param mixed $createdAt
  168. */
  169. public function setCreatedAt($createdAt){
  170. $this->createdAt = $createdAt;
  171. }
  172. /**
  173. * @param mixed $username
  174. */
  175. public function setUsername($username){
  176. $this->username = $username;
  177. }
  178. /**
  179. * @param mixed $password
  180. */
  181. public function setPassword($password) {
  182. $this->password = $password;
  183. }
  184. /**
  185. * @param mixed $roles
  186. */
  187. public function setRoles($roles){
  188. $this->roles = $roles;
  189. }
  190. /**
  191. * @return Person
  192. */
  193. public function getPerson(){
  194. return $this->person;
  195. }
  196. /**
  197. * @param Person $person
  198. */
  199. public function setPerson($person){
  200. $this->person = $person;
  201. }
  202. /**
  203. * @return mixed
  204. */
  205. public function getEmail()
  206. {
  207. return $this->email;
  208. }
  209. /**
  210. * @param mixed $email
  211. */
  212. public function setEmail($email)
  213. {
  214. $this->email = $email;
  215. }
  216. public function getUserIdentifier(): string
  217. {
  218. return $this->username;
  219. }
  220. /**
  221. * @return mixed
  222. */
  223. public function getIsActive()
  224. {
  225. return $this->isActive;
  226. }
  227. /**
  228. * @param mixed $isActive
  229. */
  230. public function setIsActive($isActive): void
  231. {
  232. $this->isActive = $isActive;
  233. }
  234. public function __toString()
  235. {
  236. // TODO: Implement __toString() method.
  237. return $this->username."";
  238. }
  239. }