<?php
namespace App\Entity;
use App\Validator\Constraints\MinAge;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @UniqueEntity("username")
* @UniqueEntity("emailAddress")
*/
class LoginPerson extends Person implements UserInterface, PasswordAuthenticatedUserInterface //, \JsonSerializable
{
/**
* @Assert\NotBlank()
* @Assert\Regex("/^[a-zA-Z0-9\-\_\.\ \@]+$/", groups={"Registration"})
* @ORM\Column(type="string")
*/
protected $username;
/**
* @ORM\Column(type="string")
*/
protected $password;
/**
* @Assert\NotBlank(groups={"Registration"})
* @Assert\Regex(pattern="/^[a-zA-Z0-9äöüÄÖÜ\-\_\.\ \@\+\:\;\?\!\§\$\%\&\/\(\)\*\#\ß\[\]\{\}]*$/", groups={"Default", "Registration"})
* @Assert\Length(min=8, groups={"Default", "Registration"})
*/
protected $plainPassword;
/**
* @ORM\Column(type="json_array", nullable=true)
*/
protected $roles = [];
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Department")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
protected $department;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $signupDate;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $apiKey;
public function __construct( $blank = false )
{
parent::__construct($blank);
if ($blank) {
$this->setSalutation('m');
$this->setFirstName('');
$this->setLastName('');
$this->setAddressStreetNo('');
$this->setAddressPostalCode('');
$this->setAddressCity('');
$this->setAddressCountry('');
$this->setDateOfBirth(new \DateTime());
$this->setEmailAddress('');
$this->setPhoneNumber('');
$this->setRoles(['ROLE_USER']);
$this->setLocale('de');
$this->setSignupDate(new \DateTime());
}
}
/**
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* @return mixed
*/
public function getRoles()
{
$roles = $this->roles;
if (!in_array('ROLE_USER', $roles)) {
$roles[] = 'ROLE_USER';
}
return $roles;
}
/**
* @param mixed $roles
*/
public function setRoles($roles)
{
$this->roles = $roles;
}
/**
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
public function getSalt()
{
// return $this->salt;
}
public function eraseCredentials()
{
$this->plainPassword = null;
}
/**
* @return mixed
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param mixed $plainPassword
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
$this->password = null;
}
/**
* @return Department|null
*/
public function getDepartment(): ?Department
{
return $this->department;
}
/**
* @param Department|null $department
*/
public function setDepartment(?Department $department): void
{
$this->department = $department;
}
/**
* @return mixed
*/
public function getSignupDate()
{
return $this->signupDate;
}
/**
* @param mixed $signupDate
*/
public function setSignupDate($signupDate): void
{
$this->signupDate = $signupDate;
}
/**
* @return string
*/
public function __toString()
{
return $this->getUsername();
}
public function serialize()
{
return serialize(
[
$this->id,
$this->emailAddress,
$this->username,
$this->password,
]
);
}
public function unserialize($serialized)
{
[
$this->id,
$this->emailAddress,
$this->username,
$this->password
] = unserialize($serialized, ['allowed_classes' => true]);
}
public function isUserdataComplete()
{
if (empty($this->salutation)) return false;
if (empty($this->firstName)) return false;
if (empty($this->lastName)) return false;
if (empty($this->addressStreetNo)) return false;
if (empty($this->addressPostalCode)) return false;
if (empty($this->addressCity)) return false;
if (empty($this->addressCountry)) return false;
if (empty($this->emailAddress)) return false;
if (empty($this->phoneNumber)) return false;
if (empty($this->dateOfBirth)) return false;
return true;
}
public function getUserIdentifier(): string
{
return $this->getUsername();
}
/**
* @return mixed
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* @param mixed $apiKey
*/
public function setApiKey($apiKey): void
{
$this->apiKey = $apiKey;
}
// public function jsonSerialize()
// {
// TODO: Implement jsonSerialize() method.
// }
}