2018-06-23 22:45:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2020-01-20 17:01:51 +00:00
|
|
|
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
2018-06-23 22:45:18 +00:00
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Table(name="users", schema="users")
|
2018-06-24 22:42:26 +00:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
2018-06-23 22:45:18 +00:00
|
|
|
*/
|
|
|
|
class User implements UserInterface, \Serializable
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\Column(name="id", type="integer")
|
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="username", type="string", length=25, unique=true)
|
|
|
|
*/
|
|
|
|
private $username;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="password", type="text")
|
|
|
|
*/
|
|
|
|
private $password;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="email", type="string", length=254, unique=true)
|
|
|
|
*/
|
|
|
|
private $email;
|
|
|
|
|
2018-06-24 22:42:26 +00:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="roles", type="json")
|
|
|
|
*/
|
|
|
|
private $roles = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \DateTime
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="created_at", type="datetime")
|
|
|
|
*/
|
|
|
|
private $createdAt;
|
|
|
|
|
2018-06-23 22:45:18 +00:00
|
|
|
/**
|
|
|
|
* @var Invite[]|ArrayCollection
|
|
|
|
*
|
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Invite", mappedBy="user", fetch="EXTRA_LAZY")
|
|
|
|
*/
|
|
|
|
private $invites;
|
|
|
|
|
2020-01-20 17:01:51 +00:00
|
|
|
public function __construct(string $username, PasswordEncoderInterface $encoder, string $rawPassword, string $email, array $roles = [])
|
2018-06-23 22:45:18 +00:00
|
|
|
{
|
|
|
|
$this->username = $username;
|
2020-01-20 17:01:51 +00:00
|
|
|
$this->password = $encoder->encodePassword($rawPassword, null);
|
2018-06-23 22:45:18 +00:00
|
|
|
$this->email = $email;
|
2018-06-24 22:42:26 +00:00
|
|
|
$this->roles = $roles ?: ['ROLE_USER'];
|
|
|
|
$this->createdAt = new \DateTime();
|
2018-06-23 22:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUsername()
|
|
|
|
{
|
|
|
|
return $this->username;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPassword()
|
|
|
|
{
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:01:51 +00:00
|
|
|
public function changePassword(PasswordEncoderInterface $encoder, string $rawPassword): void
|
2018-06-24 22:42:26 +00:00
|
|
|
{
|
2020-01-20 17:01:51 +00:00
|
|
|
$this->password = $encoder->encodePassword($rawPassword, null);
|
2018-06-24 22:42:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 22:45:18 +00:00
|
|
|
public function getSalt()
|
|
|
|
{
|
|
|
|
// Salt is not needed when using Argon2i
|
|
|
|
// @see https://symfony.com/doc/current/reference/configuration/security.html#using-the-argon2i-password-encoder
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEmail(): string
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
2018-06-24 22:42:26 +00:00
|
|
|
public function getRoles(): array
|
|
|
|
{
|
|
|
|
return $this->roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addRole(string $role): void
|
|
|
|
{
|
|
|
|
$this->roles[] = $role;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedAt(): \DateTime
|
2018-06-23 22:45:18 +00:00
|
|
|
{
|
2018-06-24 22:42:26 +00:00
|
|
|
return $this->createdAt;
|
2018-06-23 22:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function eraseCredentials()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return Invite[]|ArrayCollection */
|
|
|
|
public function getInvites(): \Traversable
|
|
|
|
{
|
|
|
|
return $this->invites;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @see \Serializable::serialize() */
|
|
|
|
public function serialize()
|
|
|
|
{
|
|
|
|
return serialize([
|
|
|
|
$this->id,
|
|
|
|
$this->username,
|
|
|
|
$this->password,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @see \Serializable::unserialize() */
|
|
|
|
public function unserialize($serialized)
|
|
|
|
{
|
2020-01-20 17:01:51 +00:00
|
|
|
[
|
2018-06-23 22:45:18 +00:00
|
|
|
$this->id,
|
|
|
|
$this->username,
|
|
|
|
$this->password
|
2020-01-20 17:01:51 +00:00
|
|
|
] = unserialize($serialized, ['allowed_classes' => false]);
|
2018-06-23 22:45:18 +00:00
|
|
|
}
|
|
|
|
}
|