src/Entity/LoginPerson.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator\Constraints\MinAge;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @UniqueEntity("username")
  11.  * @UniqueEntity("emailAddress")
  12.  */
  13. class LoginPerson extends Person implements UserInterfacePasswordAuthenticatedUserInterface //, \JsonSerializable
  14. {
  15.     /**
  16.      * @Assert\NotBlank()
  17.      * @Assert\Regex("/^[a-zA-Z0-9\-\_\.\ \@]+$/", groups={"Registration"})
  18.      * @ORM\Column(type="string")
  19.      */
  20.     protected $username;
  21.     
  22.     /**
  23.      * @ORM\Column(type="string")
  24.      */
  25.     protected $password;
  26.     
  27.     /**
  28.      * @Assert\NotBlank(groups={"Registration"})
  29.      * @Assert\Regex(pattern="/^[a-zA-Z0-9äöüÄÖÜ\-\_\.\ \@\+\:\;\?\!\§\$\%\&\/\(\)\*\#\ß\[\]\{\}]*$/", groups={"Default", "Registration"})
  30.      * @Assert\Length(min=8, groups={"Default", "Registration"})
  31.      */
  32.     protected $plainPassword;
  33.     /**
  34.      * @ORM\Column(type="json_array", nullable=true)
  35.      */
  36.     protected $roles = [];
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\Department")
  39.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  40.      */
  41.     protected $department;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     protected $signupDate;
  46.     /**
  47.      * @ORM\Column(type="string", nullable=true)
  48.      */
  49.     protected $apiKey;
  50.     public function __construct$blank false )
  51.     {
  52.         parent::__construct($blank);
  53.         if ($blank) {
  54.             $this->setSalutation('m');
  55.             $this->setFirstName('');
  56.             $this->setLastName('');
  57.             $this->setAddressStreetNo('');
  58.             $this->setAddressPostalCode('');
  59.             $this->setAddressCity('');
  60.             $this->setAddressCountry('');
  61.             $this->setDateOfBirth(new \DateTime());
  62.             $this->setEmailAddress('');
  63.             $this->setPhoneNumber('');
  64.             $this->setRoles(['ROLE_USER']);
  65.             $this->setLocale('de');
  66.             $this->setSignupDate(new \DateTime());
  67.         }
  68.     }
  69.     
  70.     /**
  71.      * @return string
  72.      */
  73.     public function getUsername()
  74.     {
  75.         return $this->username;
  76.     }
  77.     
  78.     /**
  79.      * @param string $username
  80.      */
  81.     public function setUsername($username)
  82.     {
  83.         $this->username $username;
  84.     }
  85.     
  86.     /**
  87.      * @return mixed
  88.      */
  89.     public function getRoles()
  90.     {
  91.         $roles $this->roles;
  92.         if (!in_array('ROLE_USER'$roles)) {
  93.             $roles[] = 'ROLE_USER';
  94.         }
  95.         return $roles;
  96.     }
  97.     
  98.     /**
  99.      * @param mixed $roles
  100.      */
  101.     public function setRoles($roles)
  102.     {
  103.         $this->roles $roles;
  104.     }
  105.     /**
  106.      * @return string
  107.      */
  108.     public function getPassword(): string
  109.     {
  110.         
  111.         return $this->password;
  112.     }
  113.     
  114.     /**
  115.      * @param string $password
  116.      */
  117.     public function setPassword($password)
  118.     {
  119.         $this->password $password;
  120.     }
  121.     
  122.     public function getSalt()
  123.     {
  124. //        return $this->salt;
  125.     }
  126.     
  127.     public function eraseCredentials()
  128.     {
  129.         $this->plainPassword null;
  130.     }
  131.     
  132.     /**
  133.      * @return mixed
  134.      */
  135.     public function getPlainPassword()
  136.     {
  137.         return $this->plainPassword;
  138.     }
  139.     
  140.     /**
  141.      * @param mixed $plainPassword
  142.      */
  143.     public function setPlainPassword($plainPassword)
  144.     {
  145.         $this->plainPassword $plainPassword;
  146.         $this->password null;
  147.     }
  148.     /**
  149.      * @return Department|null
  150.      */
  151.     public function getDepartment(): ?Department
  152.     {
  153.         return $this->department;
  154.     }
  155.     /**
  156.      * @param Department|null $department
  157.      */
  158.     public function setDepartment(?Department $department): void
  159.     {
  160.         $this->department $department;
  161.     }
  162.     /**
  163.      * @return mixed
  164.      */
  165.     public function getSignupDate()
  166.     {
  167.         return $this->signupDate;
  168.     }
  169.     /**
  170.      * @param mixed $signupDate
  171.      */
  172.     public function setSignupDate($signupDate): void
  173.     {
  174.         $this->signupDate $signupDate;
  175.     }
  176.     /**
  177.      * @return string
  178.      */
  179.     public function __toString()
  180.     {
  181.         return $this->getUsername();
  182.     }
  183.     
  184.     public function serialize()
  185.     {
  186.         return serialize(
  187.             [
  188.                 $this->id,
  189.                 $this->emailAddress,
  190.                 $this->username,
  191.                 $this->password,
  192.             ]
  193.         );
  194.     }
  195.     
  196.     public function unserialize($serialized)
  197.     {
  198.         [
  199.             $this->id,
  200.             $this->emailAddress,
  201.             $this->username,
  202.             $this->password
  203.         ] = unserialize($serialized, ['allowed_classes' => true]);
  204.     }
  205.     
  206.     public function isUserdataComplete()
  207.     {
  208.         if (empty($this->salutation)) return false;
  209.         if (empty($this->firstName)) return false;
  210.         if (empty($this->lastName)) return false;
  211.         if (empty($this->addressStreetNo)) return false;
  212.         if (empty($this->addressPostalCode)) return false;
  213.         if (empty($this->addressCity)) return false;
  214.         if (empty($this->addressCountry)) return false;
  215.         if (empty($this->emailAddress)) return false;
  216.         if (empty($this->phoneNumber)) return false;
  217.         if (empty($this->dateOfBirth)) return false;
  218.         
  219.         return true;
  220.     }
  221.     public function getUserIdentifier(): string
  222.     {
  223.         return $this->getUsername();
  224.     }
  225.     /**
  226.      * @return mixed
  227.      */
  228.     public function getApiKey()
  229.     {
  230.         return $this->apiKey;
  231.     }
  232.     /**
  233.      * @param mixed $apiKey
  234.      */
  235.     public function setApiKey($apiKey): void
  236.     {
  237.         $this->apiKey $apiKey;
  238.     }
  239. //    public function jsonSerialize()
  240. //    {
  241.         // TODO: Implement jsonSerialize() method.
  242. //    }
  243. }