Guest User

Untitled

a guest
Oct 18th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <?php
  2. namespace Acme\UserBundle\Entity;
  3.  
  4. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7.  
  8. /**
  9. * Acme\UserBundle\Entity\User
  10. *
  11. * @ORM\Table(name="users")
  12. * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
  13. */
  14. class User implements AdvancedUserInterface
  15. {
  16. /**
  17. * @ORM\Column(type="integer")
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\Column(type="string", length=25, unique=true)
  24. */
  25. private $username;
  26. /**
  27. * @ORM\Column(type="string", length=32)
  28. */
  29. private $salt;
  30. /**
  31. * @ORM\Column(type="string", length=40)
  32. */
  33. private $password;
  34. /**
  35. * @ORM\Column(type="string", length=60, unique=true)
  36. */
  37. private $email;
  38. /**
  39. * @ORM\Column(name="is_active", type="boolean")
  40. */
  41. private $isActive;
  42. /**
  43. * @ORM\ManyToMany(targetEntity="ACME\UserBundle\Entity\Group", inversedBy="users")
  44. */
  45. private $groups;
  46.  
  47. public function __construct()
  48. {
  49. $this->isActive = true;
  50. $this->salt = md5(uniqid(null, true));
  51. $this->groups = new ArrayCollection();
  52. }
  53. /**
  54. * @inheritDoc
  55. */
  56. public function getUsername()
  57. {
  58. return $this->username;
  59. }
  60. /**
  61. * @inheritDoc
  62. */
  63. public function getSalt()
  64. {
  65. return $this->salt;
  66. }
  67. /**
  68. * @inheritDoc
  69. */
  70. public function getPassword()
  71. {
  72. return $this->password;
  73. }
  74. /**
  75. * @inheritDoc
  76. */
  77. public function getRoles()
  78. {
  79. return $this->groups->toArray();
  80. }
  81. /**
  82. * @inheritDoc
  83. */
  84. public function eraseCredentials()
  85. {
  86. }
  87.  
  88. /**
  89. * @inheritDoc
  90. */
  91. function equals(\Symfony\Component\Security\Core\User\UserInterface $user)
  92. {
  93. return $this->username === $user->getUsername();
  94. }
  95.  
  96. /**
  97. * @inheritDoc
  98. */
  99. public function isAccountNonExpired()
  100. {
  101. return true;
  102. }
  103. /**
  104. * @inheritDoc
  105. */
  106. public function isAccountNonLocked()
  107. {
  108. return true;
  109. }
  110. /**
  111. * @inheritDoc
  112. */
  113. public function isCredentialsNonExpired()
  114. {
  115. return true;
  116. }
  117. /**
  118. * @inheritDoc
  119. */
  120. public function isEnabled()
  121. {
  122. return $this->isActive;
  123. }
  124.  
  125. public function __toString()
  126. {
  127. return $this->getId();
  128. }
  129.  
  130. /**
  131. * Get id
  132. *
  133. * @return integer
  134. */
  135. public function getId()
  136. {
  137. return $this->id;
  138. }
  139.  
  140. /**
  141. * Set username
  142. *
  143. * @param string $username
  144. */
  145. public function setUsername($username)
  146. {
  147. $this->username = $username;
  148. }
  149.  
  150. /**
  151. * Set salt
  152. *
  153. * @param string $salt
  154. */
  155. public function setSalt($salt)
  156. {
  157. $this->salt = $salt;
  158. }
  159.  
  160. /**
  161. * Set password
  162. *
  163. * @param string $password
  164. */
  165. public function setPassword($password)
  166. {
  167. $this->password = $password;
  168. }
  169.  
  170. /**
  171. * Set email
  172. *
  173. * @param string $email
  174. */
  175. public function setEmail($email)
  176. {
  177. $this->email = $email;
  178. }
  179.  
  180. /**
  181. * Get email
  182. *
  183. * @return string
  184. */
  185. public function getEmail()
  186. {
  187. return $this->email;
  188. }
  189.  
  190. /**
  191. * Set isActive
  192. *
  193. * @param boolean $isActive
  194. */
  195. public function setIsActive($isActive)
  196. {
  197. $this->isActive = $isActive;
  198. }
  199.  
  200. /**
  201. * Get isActive
  202. *
  203. * @return boolean
  204. */
  205. public function getIsActive()
  206. {
  207. return $this->isActive;
  208. }
  209.  
  210. /**
  211. * Add groups
  212. *
  213. * @param ACME\UserBundle\Entity\Group $groups
  214. */
  215. public function addGroup(\ACME\UserBundle\Entity\Group $groups)
  216. {
  217. $this->groups[] = $groups;
  218. }
  219.  
  220. /**
  221. * Get groups
  222. *
  223. * @return Doctrine\Common\Collections\Collection
  224. */
  225. public function getGroups()
  226. {
  227. return $this->groups;
  228. }
  229. }
Add Comment
Please, Sign In to add comment