<?php
namespace App\Entity\Login;
//use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Masters\MstDistrict;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="public.nicsl_users")
* @ORM\Entity
* */
class User implements UserInterface,EquatableInterface, \Serializable {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
*
* @ORM\Column(type="integer",length=1, options={ "default"=0 })
*/
protected $attempted = 0;
/**
* @ORM\Column(type="smallint",name="is_logged", options={ "default"=0 })
*/
protected $isLogged = 0;
/**
*
* @ORM\Column(type="datetime",name="attempted_at", nullable=true)
*/
protected $attemptedAt;
/**
*
* @ORM\Column(type="datetime",name="password_changed_at", nullable=true)
*/
protected $passwordChangedAt;
/**
* @ORM\Column(type="smallint",name="password_changed", options={ "default"=0 })
*/
protected $passwordChanged = 0;
/**
* @var string
*
* @ORM\Column(name="nic_password", type="string", length=255 ,nullable=true)
*/
private $nicPassword;
/**
* @var string
*
* @ORM\Column(name="gu_id", type="string", length=50,nullable=true)
*/
private $guId;
/**
* @var string
*
* @ORM\Column(type="string", unique=true, length=180)
* @Assert\NotBlank()
* @Assert\Length(min=2, max=50)
*/
private $username;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $password;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $salt;
/**
* @var array
*
* @ORM\Column(type="array")
*/
private $roles = [];
// public function __construct() {
// parent::__construct();
// // your own logic
// }
/**
* @var string
*
* @ORM\Column(name="login_check_token", type="string", length=20, nullable=true)
*/
private $loginCheckToken;
public function setCredentialsExpireAt(\DateTime $date = null) {
$date = new \DateTime('now');
$date->add(new \DateInterval('P60D'));
$this->credentialsExpireAt = $date;
return $this;
}
public function getId(): ?int {
return $this->id;
}
public function getAttempted(): ?int
{
return $this->attempted;
}
public function setAttempted(int $attempted): self
{
$this->attempted = $attempted;
return $this;
}
public function getIsLogged(): ?int
{
return $this->isLogged;
}
public function setIsLogged(int $isLogged): self
{
$this->isLogged = $isLogged;
return $this;
}
public function getAttemptedAt(): ?\DateTimeInterface
{
return $this->attemptedAt;
}
public function setAttemptedAt(?\DateTimeInterface $attemptedAt): self
{
$this->attemptedAt = $attemptedAt;
return $this;
}
public function getPasswordChangedAt(): ?\DateTimeInterface
{
return $this->passwordChangedAt;
}
public function setPasswordChangedAt(?\DateTimeInterface $passwordChangedAt): self
{
$this->passwordChangedAt = $passwordChangedAt;
return $this;
}
public function getPasswordChanged(): ?int
{
return $this->passwordChanged;
}
public function setPasswordChanged(int $passwordChanged): self
{
$this->passwordChanged = $passwordChanged;
return $this;
}
public function getNicPassword(): ?string
{
return $this->nicPassword;
}
public function setNicPassword(?string $nicPassword): self
{
$this->nicPassword = $nicPassword;
return $this;
}
public function getPassword(): ?string {
return $this->password;
}
public function setPassword(string $password): self {
$this->password = $password;
return $this;
}
public function getRoles(): ?array {
return $this->roles;
}
public function setRoles(array $roles): self {
$this->roles = $roles;
return $this;
}
public function hasRole($role) {
return in_array(strtoupper($role), $this->getRoles(), true);
}
public function getSalt(): ?string {
return $this->salt;
}
public function setSalt(?string $salt): self {
$this->salt = $salt;
return $this;
}
/**
* Removes sensitive data from the user.
*
* {@inheritdoc}
*/
public function eraseCredentials(): void {
// if you had a plainPassword property, you'd nullify it here
// $this->plainPassword = null;
}
/**
* {@inheritdoc}
*/
public function serialize(): string {
// add $this->salt too if you don't use Bcrypt or Argon2i
return serialize([$this->id, $this->username, $this->password, $this->salt]);
}
/**
* {@inheritdoc}
*/
public function unserialize($serialized): void {
// add $this->salt too if you don't use Bcrypt or Argon2i
[$this->id, $this->username, $this->password, $this->salt] = unserialize($serialized, ['allowed_classes' => false]);
}
public function isEqualTo(UserInterface $user) {
if (!$user instanceof self) {
return false;
}
if ($this->getPassword() !== $user->getPassword()) {
return false;
}
if ($this->getSalt() !== $user->getSalt()) {
return false;
}
if ($this->getUsername() !== $user->getUsername()) {
return false;
}
return true;
}
public function getUsername(): ?string {
return $this->username;
}
public function setUsername(string $username): self {
$this->username = $username;
return $this;
}
public function getLoginCheckToken(): ?string
{
return $this->loginCheckToken;
}
public function setLoginCheckToken($loginCheckToken): self
{
$this->loginCheckToken = $loginCheckToken;
return $this;
}
}