src/Entity/Login/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Login;
  3. //use FOS\UserBundle\Entity\User as BaseUser;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Entity\Masters\MstDistrict;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\EquatableInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Table(name="public.nicsl_users")
  11.  * @ORM\Entity
  12.  * */
  13. class User implements UserInterface,EquatableInterface, \Serializable {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\Column(type="integer")
  17.      * @ORM\GeneratedValue(strategy="AUTO")
  18.      */
  19.     protected $id;
  20.     /**
  21.      *
  22.      * @ORM\Column(type="integer",length=1, options={ "default"=0 })
  23.      */
  24.     protected $attempted 0;
  25.     /**
  26.      * @ORM\Column(type="smallint",name="is_logged", options={ "default"=0 })
  27.      */
  28.     protected $isLogged 0;
  29.     /**
  30.      *
  31.      * @ORM\Column(type="datetime",name="attempted_at", nullable=true)
  32.      */
  33.     protected $attemptedAt;
  34.     /**
  35.      *
  36.      * @ORM\Column(type="datetime",name="password_changed_at", nullable=true)
  37.      */
  38.     protected $passwordChangedAt;
  39.     /**
  40.      * @ORM\Column(type="smallint",name="password_changed", options={ "default"=0 })
  41.      */
  42.     protected $passwordChanged 0;
  43.     /**
  44.      * @var string
  45.      *
  46.      * @ORM\Column(name="nic_password", type="string", length=255 ,nullable=true)
  47.      */
  48.     private $nicPassword;
  49.     /**
  50.      * @var string
  51.      *
  52.      * @ORM\Column(name="gu_id", type="string", length=50,nullable=true)
  53.      */
  54.     private $guId;
  55.      /**
  56.      * @var string
  57.      *
  58.      * @ORM\Column(type="string", unique=true, length=180)
  59.      * @Assert\NotBlank()
  60.      * @Assert\Length(min=2, max=50)
  61.      */
  62.     private $username;
  63.       /**
  64.      * @var string
  65.      *
  66.      * @ORM\Column(type="string")
  67.      */
  68.     private $password;
  69.      /**
  70.      * @var string
  71.      *
  72.      * @ORM\Column(type="string", length=255, nullable=true)
  73.      */
  74.     protected $salt;
  75.      /**
  76.      * @var array
  77.      *
  78.      * @ORM\Column(type="array")
  79.      */
  80.     private $roles = [];
  81.     // public function __construct() {
  82.     //     parent::__construct();
  83.     //     // your own logic
  84.     // }
  85.     /**
  86.      * @var string
  87.      *
  88.      * @ORM\Column(name="login_check_token", type="string", length=20, nullable=true)
  89.      */
  90.     private $loginCheckToken;
  91.     public function setCredentialsExpireAt(\DateTime $date null) {
  92.         $date = new \DateTime('now');
  93.         $date->add(new \DateInterval('P60D'));
  94.         $this->credentialsExpireAt $date;
  95.         return $this;
  96.     }
  97.     public function getId(): ?int {
  98.         return $this->id;
  99.     }
  100.     public function getAttempted(): ?int
  101.     {
  102.         return $this->attempted;
  103.     }
  104.     public function setAttempted(int $attempted): self
  105.     {
  106.         $this->attempted $attempted;
  107.         return $this;
  108.     }
  109.     public function getIsLogged(): ?int
  110.     {
  111.         return $this->isLogged;
  112.     }
  113.     public function setIsLogged(int $isLogged): self
  114.     {
  115.         $this->isLogged $isLogged;
  116.         return $this;
  117.     }
  118.     public function getAttemptedAt(): ?\DateTimeInterface
  119.     {
  120.         return $this->attemptedAt;
  121.     }
  122.     public function setAttemptedAt(?\DateTimeInterface $attemptedAt): self
  123.     {
  124.         $this->attemptedAt $attemptedAt;
  125.         return $this;
  126.     }
  127.     public function getPasswordChangedAt(): ?\DateTimeInterface
  128.     {
  129.         return $this->passwordChangedAt;
  130.     }
  131.     public function setPasswordChangedAt(?\DateTimeInterface $passwordChangedAt): self
  132.     {
  133.         $this->passwordChangedAt $passwordChangedAt;
  134.         return $this;
  135.     }
  136.     public function getPasswordChanged(): ?int
  137.     {
  138.         return $this->passwordChanged;
  139.     }
  140.     public function setPasswordChanged(int $passwordChanged): self
  141.     {
  142.         $this->passwordChanged $passwordChanged;
  143.         return $this;
  144.     }
  145.     public function getNicPassword(): ?string
  146.     {
  147.         return $this->nicPassword;
  148.     }
  149.     public function setNicPassword(?string $nicPassword): self
  150.     {
  151.         $this->nicPassword $nicPassword;
  152.         return $this;
  153.     }
  154.     public function getPassword(): ?string {
  155.         return $this->password;
  156.     }
  157.     public function setPassword(string $password): self {
  158.         $this->password $password;
  159.         return $this;
  160.     }
  161.     public function getRoles(): ?array {
  162.         return $this->roles;
  163.     }
  164.     public function setRoles(array $roles): self {
  165.         $this->roles $roles;
  166.         return $this;
  167.     }
  168.     public function hasRole($role) {
  169.         return in_array(strtoupper($role), $this->getRoles(), true);
  170.     }
  171.     public function getSalt(): ?string {
  172.         return $this->salt;
  173.     }
  174.     public function setSalt(?string $salt): self {
  175.         $this->salt $salt;
  176.         return $this;
  177.     }
  178.     /**
  179.      * Removes sensitive data from the user.
  180.      *
  181.      * {@inheritdoc}
  182.      */
  183.     public function eraseCredentials(): void {
  184.         // if you had a plainPassword property, you'd nullify it here
  185.         // $this->plainPassword = null;
  186.     }
  187.     /**
  188.      * {@inheritdoc}
  189.      */
  190.     public function serialize(): string {
  191.         // add $this->salt too if you don't use Bcrypt or Argon2i
  192.         return serialize([$this->id$this->username$this->password$this->salt]);
  193.     }
  194.     /**
  195.      * {@inheritdoc}
  196.      */
  197.     public function unserialize($serialized): void {
  198.         // add $this->salt too if you don't use Bcrypt or Argon2i
  199.         [$this->id$this->username$this->password$this->salt] = unserialize($serialized, ['allowed_classes' => false]);
  200.     }
  201.     public function isEqualTo(UserInterface $user) {
  202.         if (!$user instanceof self) {
  203.             return false;
  204.         }
  205.         if ($this->getPassword() !== $user->getPassword()) {
  206.             return false;
  207.         }
  208.         if ($this->getSalt() !== $user->getSalt()) {
  209.             return false;
  210.         }
  211.         if ($this->getUsername() !== $user->getUsername()) {
  212.             return false;
  213.         }
  214.         return true;
  215.     }
  216.    
  217.     public function getUsername(): ?string {
  218.         return $this->username;
  219.     }
  220.     public function setUsername(string $username): self {
  221.         $this->username $username;
  222.         return $this;
  223.     }
  224.     public function getLoginCheckToken(): ?string
  225.     {
  226.         return $this->loginCheckToken;
  227.     }
  228.     public function setLoginCheckToken($loginCheckToken): self
  229.     {
  230.         $this->loginCheckToken $loginCheckToken;
  231.         return $this;
  232.     }
  233. }