src/Entity/Users.php line 27

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use OlaSoft\Common;
  10. use App\Repository\UsersRepository;
  11. /**
  12.  * @ORM\Entity(repositoryClass="App\Repository\UsersRepository")
  13.  * @UniqueEntity(fields="email", message="Un utilisateur existe déjà avec ce compte email.")
  14.  * @ORM\AttributeOverrides({
  15.  *      @ORM\AttributeOverride(name="email",
  16.  *          column=@ORM\Column(
  17.  *              name     = "email",
  18.  *              length   = 191,
  19.  *              unique   = true
  20.  *          )
  21.  *      )
  22.  * })
  23.  */
  24. class Users implements UserInterfacePasswordAuthenticatedUserInterface
  25. {
  26.     private $em;
  27.     public function __construct(){
  28.         $this->createdAt = new \DateTime;
  29.         $this->isEnabled false;
  30.         $this->profiles = new ArrayCollection();
  31.     }
  32.     /**
  33.      * @ORM\Column(name="id", type="integer")
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue(strategy="AUTO")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @ORM\Column(name="fName", type="string", length=255, nullable=true)
  40.      */
  41.     private $fName;
  42.     /**
  43.      * @ORM\Column(name="lName", type="string", length=255, nullable=true)
  44.      */
  45.     private $lName;
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\Column(name="phone", type="string", length=255, nullable=true)
  50.      */
  51.     private $phone;
  52.     /**
  53.      * @ORM\Column(name="email", type="string", length=255, unique=true)
  54.      */
  55.     private $email;
  56.     /**
  57.      * @ORM\Column(name="createdAt", type="datetime",nullable=true))
  58.      */
  59.     private $createdAt;
  60.     /**
  61.      * @ORM\Column(name="lastLogin", type="datetime",nullable=true))
  62.      */
  63.     private $lastLogin;
  64.     /**
  65.      * @var string The hashed password
  66.      *
  67.      * @ORM\Column(name="password", type="string", length=255,nullable=true))
  68.      */
  69.     private $password;
  70.     /**
  71.      * @ORM\Column(name="token", type="string", length=255, nullable=true))
  72.      */
  73.     private $token;
  74.     /**
  75.      * @ORM\Column(name="sex", type="boolean", nullable=true)
  76.      */
  77.     private $sex;
  78.     /**
  79.      * @ORM\Column(name="isEnabled", type="boolean", nullable=true)
  80.      */
  81.     private $isEnabled;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity="App\Entity\Profiles", inversedBy="users")
  84.      */
  85.     private $profile;
  86.     public function eraseCredentials() {}
  87.     
  88.     /**
  89.      * The public representation of the user (e.g. a username, an email address, etc.)
  90.      *
  91.      * @see UserInterface
  92.      */
  93.     public function getUserIdentifier(): string
  94.     {
  95.         return (string) $this->email;
  96.     }
  97.     /**
  98.      * @see UserInterface
  99.      */
  100.     public function getRoles(): array
  101.     {
  102.         // $roles[] = $this->profile ? $this->profile->getRole() : 'ROLE_USER';
  103.         $roles $this->profile ? [$this->profile->getRole()] : ['ROLE_USER'];
  104.         return array_unique($roles);
  105.     }
  106.     public function getSalt() {
  107.         $salt '';
  108.         return null;
  109.     }
  110.     public function getUsername() {
  111.         return $this->email;
  112.     }
  113.    /**
  114.     * @see PasswordAuthenticatedUserInterface
  115.     */
  116.     public function getPassword(): ?string
  117.     {
  118.         return $this->password;
  119.     }
  120.     // public function serialize()
  121.     // {
  122.         // return serialize(array(
  123.             // $this->id,
  124.             // $this->email,
  125.             // $this->password,
  126.         // ));
  127.     // }
  128.     // public function unserialize($serialized)
  129.     // {
  130.         // list (
  131.             // $this->id,
  132.             // $this->email,
  133.             // $this->password,
  134.         // ) = unserialize($serialized, array('allowed_classes' => false));
  135.     // }
  136.     public function getId(): ?int
  137.     {
  138.         return $this->id;
  139.     }
  140.     public function getFName(): ?string
  141.     {
  142.         return $this->fName;
  143.     }
  144.     public function setFName(?string $fName): self
  145.     {
  146.         $this->fName $fName;
  147.         return $this;
  148.     }
  149.     public function getLName(): ?string
  150.     {
  151.         return $this->lName;
  152.     }
  153.     public function setLName(?string $lName): self
  154.     {
  155.         $this->lName $lName;
  156.         return $this;
  157.     }
  158.     public function getName(): ?string
  159.     {
  160.         return $this->lName.' '.$this->fName;
  161.     }
  162.     public function getPhone(): ?string
  163.     {
  164.         return $this->phone;
  165.     }
  166.     public function setPhone(?string $phone): self
  167.     {
  168.         $this->phone $phone;
  169.         return $this;
  170.     }
  171.     public function getCreatedAt(): ?\DateTimeInterface
  172.     {
  173.         return $this->createdAt;
  174.     }
  175.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  176.     {
  177.         $this->createdAt $createdAt;
  178.         return $this;
  179.     }
  180.     public function getLastLogin(): ?\DateTimeInterface
  181.     {
  182.         return $this->lastLogin;
  183.     }
  184.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  185.     {
  186.         $this->lastLogin $lastLogin;
  187.         return $this;
  188.     }
  189.     public function setPassword(?string $password null): self
  190.     {
  191.         $this->password $password password_hash($passwordPASSWORD_BCRYPT, array('cost' => 12)) : null;
  192.         return $this;
  193.     }
  194.     public function getToken(): ?string
  195.     {
  196.         return $this->token;
  197.     }
  198.     public function setToken(?string $token): self
  199.     {
  200.         $this->token $token;
  201.         return $this;
  202.     }
  203.     public function getSex(): ?bool
  204.     {
  205.         return $this->sex;
  206.     }
  207.     public function setSex(?bool $sex): self
  208.     {
  209.         $this->sex $sex;
  210.         return $this;
  211.     }
  212.     public function getIsEnabled(): ?bool
  213.     {
  214.         return $this->isEnabled;
  215.     }
  216.     public function setIsEnabled(?bool $isEnabled): self
  217.     {
  218.         $this->isEnabled $isEnabled;
  219.         return $this;
  220.     }
  221.     public function getEmail(): ?string
  222.     {
  223.         return $this->email;
  224.     }
  225.     public function setEmail(string $email): self
  226.     {
  227.         $this->email $email;
  228.         return $this;
  229.     }
  230.     public function getProfile(): ?Profiles
  231.     {
  232.         return $this->profile;
  233.     }
  234.     public function setProfile(?Profiles $profile): self
  235.     {
  236.         $this->profile $profile;
  237.         return $this;
  238.     }
  239.     public function __toString()
  240.     {
  241.         return $this->fName." ".$this->lName;
  242.     }
  243. }