src/Entity/User.php line 25

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