|
@@ -2,328 +2,193 @@
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
+use App\Repository\UserRepository;
|
|
|
+use Doctrine\Common\Collections\Collection;
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
|
|
|
|
-/**
|
|
|
- * User
|
|
|
- *
|
|
|
- * @ORM\Table(name="user")
|
|
|
- * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
|
|
- * @UniqueEntity(fields="username", message="Le username est déjà utilisé")
|
|
|
- * @UniqueEntity(fields="mail", message="L'email est déjà utilisé")
|
|
|
- * @UniqueEntity(fields="token", message="Erreur, token non unique")
|
|
|
- *
|
|
|
- */
|
|
|
+#[ORM\Table(name: "user")]
|
|
|
+#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
|
+#[UniqueEntity(fields: "username", message: "Le username est déjà utilisé")]
|
|
|
+#[UniqueEntity(fields: "mail", message: "L'email est déjà utilisé")]
|
|
|
+#[UniqueEntity(fields: "token", message: "Erreur, token non unique")]
|
|
|
+
|
|
|
class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
{
|
|
|
- /**
|
|
|
- * @var int
|
|
|
- *
|
|
|
- * @ORM\Column(name="id", type="integer")
|
|
|
- * @ORM\Id
|
|
|
- * @ORM\GeneratedValue(strategy="AUTO")
|
|
|
- */
|
|
|
+
|
|
|
+ #[ORM\Column(name: "id", type: "integer")]
|
|
|
+ #[ORM\Id]
|
|
|
+ #[ORM\GeneratedValue(strategy: "AUTO")]
|
|
|
private $id;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="username", type="string", length=191, unique=true)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "username", type: "string", length: 191, unique: true)]
|
|
|
private $username;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="prenom", type="string", length=191, nullable=true)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "prenom", type: "string", length: 191, nullable: true)]
|
|
|
private $prenom;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="nom", type="string", length=191, nullable=true)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "nom", type: "string", length: 191, nullable: true)]
|
|
|
private $nom;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="mail", type="string", length=191, unique=true)
|
|
|
- * @Assert\Email()
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "mail", type: "string", length: 191, unique: true)]
|
|
|
+ #[Assert\Email()]
|
|
|
private $mail;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="password", type="string", length=191)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "password", type: "string", length: 191)]
|
|
|
private $password;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="token", type="string", length=191, unique=true)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "token", type: "string", length: 191, unique: true)]
|
|
|
+
|
|
|
private $token;
|
|
|
|
|
|
- /**
|
|
|
- * @var \DateTime
|
|
|
- *
|
|
|
- * @ORM\Column(name="token_validity", type="datetime")
|
|
|
- * @Assert\Type("DateTime")
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "token_validity", type: "datetime")]
|
|
|
+ #[Assert\Type("DateTime")]
|
|
|
private $tokenValidity;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- *
|
|
|
- * @ORM\Column(name="salt", type="string", length=191, nullable=true)
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "salt", type: "string", length: 191, nullable: true)]
|
|
|
private $salt;
|
|
|
|
|
|
- /**
|
|
|
- * @var boolean
|
|
|
- *
|
|
|
- * @ORM\Column(name="is_active", type="boolean")
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "is_active", type: "boolean")]
|
|
|
private $isActive;
|
|
|
|
|
|
- /**
|
|
|
- * @var array
|
|
|
- *
|
|
|
- * @ORM\Column(name="roles", type="array")
|
|
|
- */
|
|
|
+ #[ORM\Column(name: "roles", type: "array")]
|
|
|
private $roles = array();
|
|
|
|
|
|
- /**
|
|
|
- * @var \DateTime
|
|
|
- *
|
|
|
- * @ORM\Column(name="last_activity", type="datetime")
|
|
|
- * @Assert\Type("DateTime")
|
|
|
- */
|
|
|
+ #[ORM\ManyToMany(targetEntity: Film::class, mappedBy: "usersWantToView")]
|
|
|
+ private $films;
|
|
|
+
|
|
|
+ #[ORM\ManyToMany(targetEntity: Film::class, mappedBy: "usersWhoSeen")]
|
|
|
+ private $filmsVus;
|
|
|
+
|
|
|
+ #[ORM\OneToOne(targetEntity: Profile::class, mappedBy: "user", cascade: ["persist", "remove"])]
|
|
|
+ private $profile;
|
|
|
+
|
|
|
+ #[ORM\Column(name: "last_activity", type: "datetime")]
|
|
|
+ #[Assert\Type("DateTime")]
|
|
|
private $lastActivity;
|
|
|
|
|
|
- /**
|
|
|
- * @return \DateTime
|
|
|
- */
|
|
|
- public function getLastActivity()
|
|
|
+ public function getLastActivity(): ?\DateTimeInterface
|
|
|
{
|
|
|
return $this->lastActivity;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param \DateTime $lastActivity
|
|
|
- */
|
|
|
- public function setLastActivity($lastActivity)
|
|
|
+ public function setLastActivity(?\DateTimeInterface $lastActivity): self
|
|
|
{
|
|
|
$this->lastActivity = $lastActivity;
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public function isActiveNow()
|
|
|
+ public function isActiveNow(): bool
|
|
|
{
|
|
|
$delay = new \DateTime('5 minutes ago');
|
|
|
|
|
|
return ( $this->getLastActivity() > $delay );
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ORM\ManyToMany(targetEntity="App\Entity\Film", mappedBy="usersWantToView")
|
|
|
- * @var \Doctrine\Common\Collections\Collection
|
|
|
- */
|
|
|
- private $films;
|
|
|
-
|
|
|
- /**
|
|
|
- * @ORM\ManyToMany(targetEntity="App\Entity\Film", mappedBy="usersWhoSeen")
|
|
|
- * @var \Doctrine\Common\Collections\Collection
|
|
|
- */
|
|
|
- private $filmsVus;
|
|
|
-
|
|
|
- /**
|
|
|
- * @ORM\OneToOne(targetEntity=Profile::class, mappedBy="user", cascade={"persist", "remove"})
|
|
|
- */
|
|
|
- private $profile;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Get id
|
|
|
- *
|
|
|
- * @return int
|
|
|
- */
|
|
|
- public function getId()
|
|
|
+ public function getId(): ?int
|
|
|
{
|
|
|
return $this->id;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set username
|
|
|
- *
|
|
|
- * @param string $username
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function setUsername($username)
|
|
|
+ public function setUsername($username): self
|
|
|
{
|
|
|
$this->username = $username;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated since Symfony 5.3, use getUserIdentifier instead
|
|
|
- */
|
|
|
- public function getUsername()
|
|
|
+ public function getUsername(): ?string
|
|
|
{
|
|
|
return (string) $this->username;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get UserIdentifier
|
|
|
- *
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getUserIdentifier()
|
|
|
+ public function getUserIdentifier(): ?string
|
|
|
{
|
|
|
return $this->username;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param bool $activated
|
|
|
- */
|
|
|
- public function setActivated($activated)
|
|
|
+ public function setActivated($activated): self
|
|
|
{
|
|
|
$this->isActive = $activated;
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- public function getActivated()
|
|
|
+ public function getActivated(): bool
|
|
|
{
|
|
|
return $this->isActive;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getPrenom()
|
|
|
+ public function getPrenom(): ?string
|
|
|
{
|
|
|
return $this->prenom;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param string $prenom
|
|
|
- */
|
|
|
- public function setPrenom($prenom)
|
|
|
+ public function setPrenom($prenom): self
|
|
|
{
|
|
|
$this->prenom = $prenom;
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getNom()
|
|
|
+ public function getNom(): ?string
|
|
|
{
|
|
|
return $this->nom;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param string $nom
|
|
|
- */
|
|
|
- public function setNom($nom)
|
|
|
+ public function setNom($nom): self
|
|
|
{
|
|
|
$this->nom = $nom;
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getMail()
|
|
|
+ public function getMail(): ?string
|
|
|
{
|
|
|
return $this->mail;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param string $mail
|
|
|
- */
|
|
|
- public function setMail($mail)
|
|
|
+ public function setMail($mail): self
|
|
|
{
|
|
|
$this->mail = $mail;
|
|
|
- }
|
|
|
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Set password
|
|
|
- *
|
|
|
- * @param string $password
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function setPassword($password)
|
|
|
+ public function setPassword($password): self
|
|
|
{
|
|
|
$this->password = $password;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get password
|
|
|
- *
|
|
|
- * @return string
|
|
|
- */
|
|
|
public function getPassword() : ?string
|
|
|
{
|
|
|
return $this->password;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set salt
|
|
|
- *
|
|
|
- * @param string $salt
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function setSalt($salt)
|
|
|
+ public function setSalt($salt): self
|
|
|
{
|
|
|
$this->salt = $salt;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get salt
|
|
|
- *
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getSalt()
|
|
|
+ public function getSalt(): ?string
|
|
|
{
|
|
|
return $this->salt;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get token
|
|
|
- *
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getToken()
|
|
|
+ public function getToken(): ?string
|
|
|
{
|
|
|
return $this->token;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set token
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function setToken($token)
|
|
|
+ public function setToken($token): self
|
|
|
{
|
|
|
//$this->token = hash("sha512", uniqid());
|
|
|
$this->token = $token;
|
|
@@ -332,51 +197,27 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get token_validity
|
|
|
- *
|
|
|
- * @return \DateTime
|
|
|
- */
|
|
|
- public function getTokenValidity()
|
|
|
+ public function getTokenValidity(): ?\DateTimeInterface
|
|
|
{
|
|
|
return $this->tokenValidity;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set token
|
|
|
- *
|
|
|
- * @param \DateTime $tokenValidity
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- private function setTokenValidity(\DateTime $tokenValidity)
|
|
|
+ private function setTokenValidity(\DateTimeInterface $tokenValidity)
|
|
|
{
|
|
|
$this->tokenValidity = $tokenValidity;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Is ValidToken
|
|
|
- *
|
|
|
- * @return boolean
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
- public function isValidToken()
|
|
|
+ public function isValidToken(): bool
|
|
|
{
|
|
|
- $expire = $this->getTokenValidity()->modify('+1 hour');
|
|
|
+ $expire = (new \DateTime($this->getTokenValidity()->format("Y-m-d H:i:s")))->modify('+1 hour');
|
|
|
+ dump($expire);
|
|
|
+ dump(new \DateTime('now'));
|
|
|
return ( $expire > new \DateTime('now') );
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set roles
|
|
|
- *
|
|
|
- * @param array $roles
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function setRoles($roles)
|
|
|
+ public function setRoles($roles): self
|
|
|
{
|
|
|
$this->roles = $roles;
|
|
|
|
|
@@ -384,22 +225,20 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get roles
|
|
|
- *
|
|
|
- * @return array
|
|
|
+ * @see UserInterface
|
|
|
*/
|
|
|
- public function getRoles()
|
|
|
+ public function getRoles(): array
|
|
|
{
|
|
|
- return $this->roles;
|
|
|
+ $roles = $this->roles;
|
|
|
+ return array_unique($roles);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public function eraseCredentials()
|
|
|
+ public function eraseCredentials(): void
|
|
|
{
|
|
|
|
|
|
}
|
|
|
- /**
|
|
|
- * Constructor
|
|
|
- */
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->films = new \Doctrine\Common\Collections\ArrayCollection();
|
|
@@ -409,80 +248,48 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
- /**
|
|
|
- * Add film
|
|
|
- *
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function addFilm(\App\Entity\Film $film)
|
|
|
+
|
|
|
+ public function addFilm(\App\Entity\Film $film): self
|
|
|
{
|
|
|
$this->films[] = $film;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Remove film
|
|
|
- *
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- */
|
|
|
- public function removeFilm(\App\Entity\Film $film)
|
|
|
+ public function removeFilm(\App\Entity\Film $film): self
|
|
|
{
|
|
|
$this->films->removeElement($film);
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get films
|
|
|
- *
|
|
|
- * @return \Doctrine\Common\Collections\Collection
|
|
|
- */
|
|
|
- public function getFilms()
|
|
|
+ public function getFilms(): Collection
|
|
|
{
|
|
|
return $this->films;
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
- /**
|
|
|
- * Add film
|
|
|
- *
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- *
|
|
|
- * @return User
|
|
|
- */
|
|
|
- public function addFilmVu(\App\Entity\Film $film)
|
|
|
+
|
|
|
+ public function addFilmVu(\App\Entity\Film $film): self
|
|
|
{
|
|
|
$this->filmsVus[] = $film;
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Remove film
|
|
|
- *
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- */
|
|
|
- public function removeFilmVu(\App\Entity\Film $film)
|
|
|
+ public function removeFilmVu(\App\Entity\Film $film): self
|
|
|
{
|
|
|
$this->filmsVus->removeElement($film);
|
|
|
+
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get films
|
|
|
- *
|
|
|
- * @return \Doctrine\Common\Collections\Collection
|
|
|
- */
|
|
|
- public function getFilmsVus()
|
|
|
+ public function getFilmsVus(): Collection
|
|
|
{
|
|
|
return $this->filmsVus;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get nomComplet
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getNomComplet()
|
|
|
+ public function getNomComplet(): ?string
|
|
|
{
|
|
|
if ($this->prenom == null && $this->nom == null)
|
|
|
{
|
|
@@ -491,28 +298,27 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
return $this->getPrenom()." ".$this->getNom();
|
|
|
}
|
|
|
|
|
|
- public function isAccountNonExpired()
|
|
|
+ public function isAccountNonExpired(): bool
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public function isAccountNonLocked()
|
|
|
+ public function isAccountNonLocked(): bool
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public function isCredentialsNonExpired()
|
|
|
+ public function isCredentialsNonExpired(): bool
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public function isEnabled()
|
|
|
+ public function isEnabled(): bool
|
|
|
{
|
|
|
return $this->isActive;
|
|
|
}
|
|
|
|
|
|
- /** @see \Serializable::serialize() */
|
|
|
- public function serialize()
|
|
|
+ public function serialize(): ?string
|
|
|
{
|
|
|
return serialize(array(
|
|
|
$this->id,
|
|
@@ -524,8 +330,7 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- /** @see \Serializable::unserialize() */
|
|
|
- public function unserialize($serialized)
|
|
|
+ public function unserialize($serialized):void
|
|
|
{
|
|
|
list (
|
|
|
$this->id,
|
|
@@ -538,20 +343,12 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
|
|
|
) = unserialize($serialized, array('allowed_classes' => false));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public function wantToSee(Film $film)
|
|
|
+ public function wantToSee(Film $film): bool
|
|
|
{
|
|
|
return $this->getFilms()->contains($film);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param \App\Entity\Film $film
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public function haveSeen(Film $film)
|
|
|
+ public function haveSeen(Film $film): bool
|
|
|
{
|
|
|
return $this->getFilmsVus()->contains($film);
|
|
|
}
|