123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <?php
- namespace AppBundle\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- 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;
- /**
- * User
- *
- * @ORM\Table(name="user")
- * @ORM\Entity(repositoryClass="AppBundle\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")
- *
- */
- class User implements UserInterface
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="username", type="string", length=255, unique=true)
- */
- private $username;
- /**
- * @var string
- *
- * @ORM\Column(name="prenom", type="string", length=255)
- */
- private $prenom;
- /**
- * @var string
- *
- * @ORM\Column(name="nom", type="string", length=255)
- */
- private $nom;
- /**
- * @var string
- *
- * @ORM\Column(name="mail", type="string", length=255, unique=true)
- */
- private $mail;
- /**
- * @var string
- *
- * @ORM\Column(name="password", type="string", length=255)
- */
- private $password;
- /**
- * @var string
- *
- * @ORM\Column(name="token", type="string", length=255, unique=true)
- */
- private $token;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="token_validity", type="datetime")
- */
- private $tokenValidity;
- /**
- * @var string
- *
- * @ORM\Column(name="salt", type="string", length=255, nullable=true)
- */
- private $salt;
- /**
- * @var array
- *
- * @ORM\Column(name="roles", type="array")
- */
- private $roles = array();
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="last_activity", type="datetime")
- */
- private $lastActivity;
- /**
- * @return \DateTime
- */
- public function getLastActivity()
- {
- return $this->lastActivity;
- }
- /**
- * @param \DateTime $lastActivity
- */
- public function setLastActivity($lastActivity)
- {
- $this->lastActivity = $lastActivity;
- }
- /**
- * @return boolean
- */
- public function isActiveNow()
- {
- $delay = new \DateTime('2 minutes ago');
- return ( $this->getLastActivity() > $delay );
- }
- /**
- * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Film", mappedBy="usersWantToView")
- * @var \Doctrine\Common\Collections\Collection
- */
- private $films;
- /**
- * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Film", mappedBy="usersWhoSeen")
- * @var \Doctrine\Common\Collections\Collection
- */
- private $filmsVus;
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set username
- *
- * @param string $username
- *
- * @return User
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
- /**
- * Get username
- *
- * @return string
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * @return string
- */
- public function getPrenom()
- {
- return $this->prenom;
- }
- /**
- * @param string $prenom
- */
- public function setPrenom($prenom)
- {
- $this->prenom = $prenom;
- }
- /**
- * @return string
- */
- public function getNom()
- {
- return $this->nom;
- }
- /**
- * @param string $nom
- */
- public function setNom($nom)
- {
- $this->nom = $nom;
- }
- /**
- * @return string
- */
- public function getMail()
- {
- return $this->mail;
- }
- /**
- * @param string $mail
- */
- public function setMail($mail)
- {
- $this->mail = $mail;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return User
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set salt
- *
- * @param string $salt
- *
- * @return User
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- return $this;
- }
- /**
- * Get salt
- *
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Get token
- *
- * @return string
- */
- public function getToken()
- {
- return $this->token;
- }
- /**
- * Set token
- *
- * @return User
- */
- public function setToken()
- {
- $this->token = hash("sha512", uniqid());
- $this->setTokenValidity(new \DateTime());
- return $this;
- }
- /**
- * Get token_validity
- *
- * @return \DateTime
- */
- public function getTokenValidity()
- {
- return $this->tokenValidity;
- }
- /**
- * Set token
- *
- * @param \DateTime $tokenValidity
- *
- * @return User
- */
- private function setTokenValidity(\DateTime $tokenValidity)
- {
- $this->tokenValidity = $tokenValidity;
- return $this;
- }
- /**
- * Is ValidToken
- *
- * @return boolean
- *
- */
- public function isValidToken()
- {
- $expire = $this->getTokenValidity()->modify('+1 hour');
- return ( $expire > new \DateTime('now') );
- }
- /**
- * Set roles
- *
- * @param array $roles
- *
- * @return User
- */
- public function setRoles($roles)
- {
- $this->roles = $roles;
- return $this;
- }
- /**
- * Get roles
- *
- * @return array
- */
- public function getRoles()
- {
- return $this->roles;
- }
- public function eraseCredentials()
- {
- }
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->films = new \Doctrine\Common\Collections\ArrayCollection();
- $this->setToken();
- $this->setLastActivity(new \DateTime('now'));
- }
- ///////////////////////////////////////////////////////////////
- /**
- * Add film
- *
- * @param \AppBundle\Entity\Film $film
- *
- * @return User
- */
- public function addFilm(\AppBundle\Entity\Film $film)
- {
- $this->films[] = $film;
- return $this;
- }
- /**
- * Remove film
- *
- * @param \AppBundle\Entity\Film $film
- */
- public function removeFilm(\AppBundle\Entity\Film $film)
- {
- $this->films->removeElement($film);
- }
- /**
- * Get films
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getFilms()
- {
- return $this->films;
- }
- ///////////////////////////////////////////////////////////////////////////
- /**
- * Add film
- *
- * @param \AppBundle\Entity\Film $film
- *
- * @return User
- */
- public function addFilmVu(\AppBundle\Entity\Film $film)
- {
- $this->filmsVus[] = $film;
- return $this;
- }
- /**
- * Remove film
- *
- * @param \AppBundle\Entity\Film $film
- */
- public function removeFilmVu(\AppBundle\Entity\Film $film)
- {
- $this->filmsVus->removeElement($film);
- }
- /**
- * Get films
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getFilmsVus()
- {
- return $this->filmsVus;
- }
- /**
- * Get nomComplet
- * @return string
- */
- public function getNomComplet()
- {
- return $this->getPrenom()." ".$this->getNom();
- }
- }
|