Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Doctrine\Common\Collections\ArrayCollection;
- /**
- * @ORM\Table(name="users")
- * @ORM\Entity
- */
- class User implements UserInterface
- {
- /**
- * @ORM\Column(type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @ORM\Column(type="string", length=25, unique=true)
- */
- private $username;
- /**
- * @ORM\Column(type="string", length=500)
- */
- private $password;
- /**
- * @ORM\Column(name="is_active", type="boolean")
- */
- private $isActive;
- /**
- * @ORM\ManyToMany(targetEntity="App\Entity\Role", mappedBy="users")
- */
- private $userRoles;
- private $nb_request_max;
- public function __construct($username)
- {
- $this->isActive = true;
- $this->userRoles = new ArrayCollection();
- $this->username = $username;
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function getSalt()
- {
- return null;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * Returns the roles granted to the user.
- *
- * public function getRoles()
- * {
- * return array('ROLE_USER');
- * }
- *
- * Alternatively, the roles might be stored on a ``roles`` property,
- * and populated in any number of different ways when the user object
- * is created.
- *
- * @return (Role|string)[] The user roles
- */
- public function getRoles()
- {
- $roles = $this->userRoles->map(function ($role){
- return $role->getTitle();
- })->toArray();
- $roles[] = 'ROLE_USER';
- return $roles;
- }
- /**
- * @return Collection|Role[]
- */
- public function getUserRoles(): Collection
- {
- return $this->userRoles;
- }
- public function addUserRole(Role $userRole): self
- {
- if (!$this->userRoles->contains($userRole)) {
- $this->userRoles[] = $userRole;
- $userRole->addUser($this);
- }
- return $this;
- }
- public function eraseCredentials()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement