<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Traits\CreatedUpdatedTrait;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\ExclusionPolicy;
use Symfony\Component\Security\Core\User\UserInterface;
//use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
/**
* @ORM\Table(name="v_clinic_user")
* @ORM\Entity()
* @ExclusionPolicy("all")
*/
//class ClinicUser implements UserInterface, TwoFactorInterface
class ClinicUser implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Expose
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Clinic")
* @Expose
*/
private $clinic;
/**
* @ORM\Column(type="string", length=255)
* @Expose
*/
private $name;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Expose
*/
private $email;
/**
* @ORM\Column(type="string", length=80, nullable=true)
* @Expose
*/
private $phone;
/**
* @var string[]
* @ORM\Column(type="json", nullable=true)
*/
private $roles;
/**
* @var string Salt
* @ORM\Column(type="string")
*/
private $salt;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* Plain password. Used for model validation. Must not be persisted.
* @var string
*/
private $plainPassword;
/**
* @var boolean
* @ORM\Column(type="boolean")
* @Expose
*/
private $confirmed = true;
/**
* @var boolean
* @ORM\Column(type="boolean")
* @Expose
*/
private $enabled = true;
/**
* @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
*/
private $googleAuthenticatorSecret;
use CreatedUpdatedTrait;
public function __construct()
{
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$this->email = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$this->password = '123456';
}
public function __toString()
{
return (string) $this->name;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return mixed
*/
public function getClinic()
{
return $this->clinic;
}
/**
* @param mixed $clinic
*/
public function setClinic($clinic): void
{
$this->clinic = $clinic;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name): void
{
$this->name = $name;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param mixed $phone
*/
public function setPhone($phone): void
{
$this->phone = $phone;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
/**
* @param string $plainPassword
*/
public function setPlainPassword(string $plainPassword): void
{
$this->plainPassword = $plainPassword;
}
/**
* @return string|void|null
*/
public function getSalt()
{
$this->salt;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return bool
*/
public function isConfirmed(): bool
{
return $this->confirmed;
}
/**
* @param bool $confirmed
*/
public function setConfirmed(bool $confirmed): void
{
$this->confirmed = $confirmed;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @param bool $enabled
*/
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}
public function isGoogleAuthenticatorEnabled(): bool
{
return $this->googleAuthenticatorSecret ? true : false;
}
public function getGoogleAuthenticatorUsername(): string
{
return $this->email;
}
public function getGoogleAuthenticatorSecret(): ?string
{
return $this->googleAuthenticatorSecret;
}
public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
{
$this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
}
}