Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. /**
  7. * @ORM\Table(name="users")
  8. * @ORM\Entity
  9. */
  10. class User implements UserInterface
  11. {
  12. /**
  13. * @ORM\Column(type="integer")
  14. * @ORM\Id
  15. * @ORM\GeneratedValue(strategy="AUTO")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=25, unique=true)
  20. */
  21. private $username;
  22. /**
  23. * @ORM\Column(type="string", length=500)
  24. */
  25. private $password;
  26. /**
  27. * @ORM\Column(name="is_active", type="boolean")
  28. */
  29. private $isActive;
  30. /**
  31. * @ORM\ManyToMany(targetEntity="App\Entity\Role", mappedBy="users")
  32. */
  33. private $userRoles;
  34.  
  35. private $nb_request_max;
  36. public function __construct($username)
  37. {
  38. $this->isActive = true;
  39. $this->userRoles = new ArrayCollection();
  40. $this->username = $username;
  41. }
  42. public function getUsername()
  43. {
  44. return $this->username;
  45. }
  46. public function getSalt()
  47. {
  48. return null;
  49. }
  50. public function getPassword()
  51. {
  52. return $this->password;
  53. }
  54. public function setPassword($password)
  55. {
  56. $this->password = $password;
  57. }
  58. /**
  59. * Returns the roles granted to the user.
  60. *
  61. * public function getRoles()
  62. * {
  63. * return array('ROLE_USER');
  64. * }
  65. *
  66. * Alternatively, the roles might be stored on a ``roles`` property,
  67. * and populated in any number of different ways when the user object
  68. * is created.
  69. *
  70. * @return (Role|string)[] The user roles
  71. */
  72. public function getRoles()
  73. {
  74. $roles = $this->userRoles->map(function ($role){
  75. return $role->getTitle();
  76. })->toArray();
  77. $roles[] = 'ROLE_USER';
  78. return $roles;
  79. }
  80. /**
  81. * @return Collection|Role[]
  82. */
  83. public function getUserRoles(): Collection
  84. {
  85. return $this->userRoles;
  86. }
  87. public function addUserRole(Role $userRole): self
  88. {
  89. if (!$this->userRoles->contains($userRole)) {
  90. $this->userRoles[] = $userRole;
  91. $userRole->addUser($this);
  92. }
  93. return $this;
  94. }
  95. public function eraseCredentials()
  96. {
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement