src/Entity/ClinicUser.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Traits\CreatedUpdatedTrait;
  5. use JMS\Serializer\Annotation\Expose;
  6. use JMS\Serializer\Annotation\ExclusionPolicy;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. //use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
  9. /**
  10.  * @ORM\Table(name="v_clinic_user")
  11.  * @ORM\Entity()
  12.  * @ExclusionPolicy("all")
  13.  */
  14. //class ClinicUser implements UserInterface, TwoFactorInterface
  15. class ClinicUser implements UserInterface
  16. {
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      * @Expose
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity="App\Entity\Clinic")
  26.      * @Expose
  27.      */
  28.     private $clinic;
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      * @Expose
  32.      */
  33.     private $name;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, unique=true)
  36.      * @Expose
  37.      */
  38.     private $email;
  39.     /**
  40.      * @ORM\Column(type="string", length=80, nullable=true)
  41.      * @Expose
  42.      */
  43.     private $phone;
  44.     /**
  45.      * @var string[]
  46.      * @ORM\Column(type="json", nullable=true)
  47.      */
  48.     private $roles;
  49.     /**
  50.      * @var string Salt
  51.      * @ORM\Column(type="string")
  52.      */
  53.     private $salt;
  54.     /**
  55.      * @var string The hashed password
  56.      * @ORM\Column(type="string")
  57.      */
  58.     private $password;
  59.     /**
  60.      * Plain password. Used for model validation. Must not be persisted.
  61.      * @var string
  62.      */
  63.     private $plainPassword;
  64.     /**
  65.      * @var boolean
  66.      * @ORM\Column(type="boolean")
  67.      * @Expose
  68.      */
  69.     private $confirmed true;
  70.     /**
  71.      * @var boolean
  72.      * @ORM\Column(type="boolean")
  73.      * @Expose
  74.      */
  75.     private $enabled true;
  76.     /**
  77.      * @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
  78.      */
  79.     private $googleAuthenticatorSecret;
  80.     use CreatedUpdatedTrait;
  81.     public function __construct()
  82.     {
  83.         $this->salt base_convert(sha1(uniqid(mt_rand(), true)), 1636);
  84.         $this->email base_convert(sha1(uniqid(mt_rand(), true)), 1636);
  85.         $this->password '123456';
  86.     }
  87.     public function __toString()
  88.     {
  89.         return (string) $this->name;
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     /**
  96.      * @return mixed
  97.      */
  98.     public function getClinic()
  99.     {
  100.         return $this->clinic;
  101.     }
  102.     /**
  103.      * @param mixed $clinic
  104.      */
  105.     public function setClinic($clinic): void
  106.     {
  107.         $this->clinic $clinic;
  108.     }
  109.     /**
  110.      * @return mixed
  111.      */
  112.     public function getName()
  113.     {
  114.         return $this->name;
  115.     }
  116.     /**
  117.      * @param mixed $name
  118.      */
  119.     public function setName($name): void
  120.     {
  121.         $this->name $name;
  122.     }
  123.     public function getEmail(): ?string
  124.     {
  125.         return $this->email;
  126.     }
  127.     public function setEmail(string $email): self
  128.     {
  129.         $this->email $email;
  130.         return $this;
  131.     }
  132.     /**
  133.      * @return mixed
  134.      */
  135.     public function getPhone()
  136.     {
  137.         return $this->phone;
  138.     }
  139.     /**
  140.      * @param mixed $phone
  141.      */
  142.     public function setPhone($phone): void
  143.     {
  144.         $this->phone $phone;
  145.     }
  146.     /**
  147.      * A visual identifier that represents this user.
  148.      *
  149.      * @see UserInterface
  150.      */
  151.     public function getUsername(): string
  152.     {
  153.         return (string) $this->email;
  154.     }
  155.     /**
  156.      * @see UserInterface
  157.      */
  158.     public function getRoles(): array
  159.     {
  160.         $roles $this->roles;
  161.         // guarantee every user at least has ROLE_USER
  162.         $roles[] = 'ROLE_USER';
  163.         return array_unique($roles);
  164.     }
  165.     public function setRoles(array $roles): self
  166.     {
  167.         $this->roles $roles;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @see UserInterface
  172.      */
  173.     public function getPassword(): string
  174.     {
  175.         return (string) $this->password;
  176.     }
  177.     public function setPassword(string $password): self
  178.     {
  179.         $this->password $password;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return string
  184.      */
  185.     public function getPlainPassword(): ?string
  186.     {
  187.         return $this->plainPassword;
  188.     }
  189.     /**
  190.      * @param string $plainPassword
  191.      */
  192.     public function setPlainPassword(string $plainPassword): void
  193.     {
  194.         $this->plainPassword $plainPassword;
  195.     }
  196.     /**
  197.      * @return string|void|null
  198.      */
  199.     public function getSalt()
  200.     {
  201.         $this->salt;
  202.     }
  203.     /**
  204.      * @see UserInterface
  205.      */
  206.     public function eraseCredentials()
  207.     {
  208.         // If you store any temporary, sensitive data on the user, clear it here
  209.         // $this->plainPassword = null;
  210.     }
  211.     /**
  212.      * @return bool
  213.      */
  214.     public function isConfirmed(): bool
  215.     {
  216.         return $this->confirmed;
  217.     }
  218.     /**
  219.      * @param bool $confirmed
  220.      */
  221.     public function setConfirmed(bool $confirmed): void
  222.     {
  223.         $this->confirmed $confirmed;
  224.     }
  225.     /**
  226.      * @return bool
  227.      */
  228.     public function isEnabled(): bool
  229.     {
  230.         return $this->enabled;
  231.     }
  232.     /**
  233.      * @param bool $enabled
  234.      */
  235.     public function setEnabled(bool $enabled): void
  236.     {
  237.         $this->enabled $enabled;
  238.     }
  239.     public function isGoogleAuthenticatorEnabled(): bool
  240.     {
  241.         return $this->googleAuthenticatorSecret true false;
  242.     }
  243.     public function getGoogleAuthenticatorUsername(): string
  244.     {
  245.         return $this->email;
  246.     }
  247.     public function getGoogleAuthenticatorSecret(): ?string
  248.     {
  249.         return $this->googleAuthenticatorSecret;
  250.     }
  251.     public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
  252.     {
  253.         $this->googleAuthenticatorSecret $googleAuthenticatorSecret;
  254.     }
  255. }