Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Ndrm\AuthBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  9. use \Doctrine\Common\Collections\ArrayCollection;
  10.  
  11. /**
  12. * User
  13. *
  14. * @ORM\Table(name="users")
  15. * @ORM\Entity(repositoryClass="Ndrm\AuthBundle\Repository\UserRepository")
  16. * @UniqueEntity(fields="email", message="Email already taken")
  17. * @UniqueEntity(fields="username", message="username already taken")
  18. * @UniqueEntity(fields="cellPhone", message="Cell phone already taken")
  19. */
  20. class User implements AdvancedUserInterface, \Serializable {
  21.  
  22. /**
  23. * @var int
  24. *
  25. * @ORM\Column(name="id_users", type="integer")
  26. * @ORM\Id
  27. * @ORM\GeneratedValue(strategy="AUTO")
  28. */
  29. private $id;
  30.  
  31. /**
  32. * @var string
  33. *
  34. * @ORM\Column(name="username", type="string", length=25, unique=true)
  35. * @Assert\NotBlank()
  36. */
  37. private $username;
  38.  
  39. /**
  40. * @ORM\Column(name="password",type="string", length=64)
  41. */
  42. private $password;
  43.  
  44. /**
  45. * Not in databse will be encrypted
  46. * @Assert\NotBlank()
  47. * @Assert\Length(max=4096)
  48. */
  49. private $plainPassword;
  50.  
  51. /**
  52. * @ORM\Column(name="email",type="string", length=60, unique=true)
  53. * @Assert\NotBlank()
  54. * @Assert\Email()
  55. */
  56. private $email;
  57.  
  58. /**
  59. * @ORM\Column(name="cell_phone",type="string", length=10, unique=true)
  60. * @Assert\NotBlank()
  61. */
  62. private $cellPhone;
  63.  
  64. /**
  65. * @ORM\Column(name="is_active", type="boolean")
  66. */
  67. private $isActive;
  68.  
  69. /**
  70. * @ORM\Column(name="first_name", type="string")
  71. * @Assert\NotBlank()
  72. */
  73. private $firstName;
  74.  
  75. /**
  76. * @ORM\Column(name="last_name", type="string")
  77. * @Assert\NotBlank()
  78. */
  79. private $lastName;
  80.  
  81. /**
  82. *
  83. * @var string
  84. */
  85. private $remember;
  86.  
  87. /**
  88. * Many User have Many Role.
  89. * @ORM\ManyToMany(targetEntity="Role")
  90. * @ORM\JoinTable(name="users_roles",
  91. * joinColumns={@ORM\JoinColumn(name="id_users", referencedColumnName="id_users")},
  92. * inverseJoinColumns={@ORM\JoinColumn(name="id_roles", referencedColumnName="id_roles")}
  93. * )
  94. */
  95. private $roles;
  96.  
  97. public function __construct() {
  98. $this->isActive = true;
  99. $this->roles = new ArrayCollection();
  100. }
  101.  
  102. function getId() {
  103. return $this->id;
  104. }
  105.  
  106. function getIsActive() {
  107. return $this->isActive;
  108. }
  109.  
  110. public function getSalt() {
  111.  
  112. }
  113.  
  114. public function getUsername() {
  115. return $this->username;
  116. }
  117.  
  118. public function getPassword() {
  119. return $this->password;
  120. }
  121.  
  122. public function getRoles() {
  123. return $this->roles->toArray();
  124. }
  125.  
  126. public function getRolesIds() {
  127. $rolesIds = array();
  128. if (is_array($this->getRoles())) {
  129. foreach ($this->getRoles() as $roleObject) {
  130. $rolesIds[] = $roleObject->getId();
  131. }
  132. }
  133. return $rolesIds;
  134. }
  135.  
  136. public function eraseCredentials() {
  137.  
  138. }
  139.  
  140. /** @see \Serializable::serialize() */
  141. public function serialize() {
  142. return json_encode(array(
  143. $this->id,
  144. $this->username,
  145. $this->password,
  146. $this->roles
  147. ));
  148. }
  149.  
  150. /** @see \Serializable::unserialize() */
  151. public function unserialize($serialized) {
  152. list (
  153. $this->id,
  154. $this->username,
  155. $this->password,
  156. $this->roles
  157. ) = json_decode($serialized);
  158. }
  159.  
  160. function getEmail() {
  161. return $this->email;
  162. }
  163.  
  164. function setEmail($email) {
  165. $this->email = $email;
  166. }
  167.  
  168. function getFirstName() {
  169. return $this->firstName;
  170. }
  171.  
  172. function getLastName() {
  173. return $this->lastName;
  174. }
  175.  
  176. function setFirstName($firstName) {
  177. $this->firstName = $firstName;
  178. }
  179.  
  180. function setLastName($lastName) {
  181. $this->lastName = $lastName;
  182. }
  183.  
  184. function getCellPhone() {
  185. return $this->cellPhone;
  186. }
  187.  
  188. function setCellPhone($cellPhone) {
  189. $this->cellPhone = $cellPhone;
  190. }
  191.  
  192. function setUsername($username) {
  193. $this->username = $username;
  194. }
  195.  
  196. function setPassword($password) {
  197. $this->password = $password;
  198. }
  199.  
  200. function setPlainPassword($plainPassword) {
  201. $this->plainPassword = $plainPassword;
  202. }
  203.  
  204. function getPlainPassword() {
  205. return $this->plainPassword;
  206. }
  207.  
  208. public function isAccountNonExpired(): bool {
  209. return true;
  210. }
  211.  
  212. public function isAccountNonLocked(): bool {
  213. return true;
  214. }
  215.  
  216. public function isCredentialsNonExpired(): bool {
  217. return true;
  218. }
  219.  
  220. public function isEnabled(): bool {
  221. return true;
  222. }
  223.  
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement