2015-01-22 16:18:56 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-23 15:28:37 +00:00
|
|
|
namespace Wallabag\CoreBundle\Entity;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2015-02-06 14:18:54 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2015-01-22 16:18:56 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2015-01-31 14:14:10 +00:00
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
|
2015-02-17 21:45:20 +00:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2015-02-20 10:45:38 +00:00
|
|
|
use JMS\Serializer\Annotation\ExclusionPolicy;
|
|
|
|
use JMS\Serializer\Annotation\Expose;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 13:18:01 +00:00
|
|
|
* User
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\Table(name="user")
|
2015-03-28 13:27:45 +00:00
|
|
|
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks()
|
2015-02-20 10:45:38 +00:00
|
|
|
* @ExclusionPolicy("all")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-02-06 13:18:01 +00:00
|
|
|
class User implements AdvancedUserInterface, \Serializable
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var integer
|
|
|
|
*
|
2015-02-20 10:45:38 +00:00
|
|
|
* @Expose
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\Column(name="id", type="integer")
|
2015-01-22 16:18:56 +00:00
|
|
|
* @ORM\Id
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\Column(name="username", type="text")
|
2015-02-17 21:45:20 +00:00
|
|
|
* @Assert\NotBlank()
|
|
|
|
* @Assert\Length(
|
|
|
|
* min = "3",
|
|
|
|
* max = "255"
|
|
|
|
* )
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
private $username;
|
|
|
|
|
2015-01-31 14:14:10 +00:00
|
|
|
/**
|
2015-02-06 13:18:01 +00:00
|
|
|
* @var string
|
|
|
|
*
|
2015-01-31 14:14:10 +00:00
|
|
|
* @ORM\Column(type="string", length=32)
|
|
|
|
*/
|
|
|
|
private $salt;
|
|
|
|
|
2015-01-22 16:18:56 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\Column(name="password", type="text")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
private $password;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="name", type="text", nullable=true)
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2015-02-17 21:45:20 +00:00
|
|
|
* @ORM\Column(name="email", type="text", nullable=false)
|
|
|
|
* @Assert\Email()
|
|
|
|
* @Assert\NotBlank()
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
private $email;
|
|
|
|
|
2015-01-31 14:14:10 +00:00
|
|
|
/**
|
2015-02-17 21:45:20 +00:00
|
|
|
* @ORM\Column(name="is_active", type="boolean", nullable=false)
|
2015-01-31 14:14:10 +00:00
|
|
|
*/
|
2015-02-17 21:45:20 +00:00
|
|
|
private $isActive = true;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2015-03-07 22:25:36 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="confirmation_token", type="string", nullable=true)
|
|
|
|
*/
|
|
|
|
private $confirmationToken;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
|
|
|
|
*/
|
|
|
|
private $passwordRequestedAt;
|
|
|
|
|
2015-02-06 13:18:01 +00:00
|
|
|
/**
|
|
|
|
* @var date
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="created_at", type="datetime")
|
|
|
|
*/
|
|
|
|
private $createdAt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var date
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="updated_at", type="datetime")
|
|
|
|
*/
|
|
|
|
private $updatedAt;
|
|
|
|
|
2015-02-06 14:18:54 +00:00
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
|
|
|
|
*/
|
|
|
|
private $entries;
|
|
|
|
|
2015-02-23 21:55:06 +00:00
|
|
|
/**
|
|
|
|
* @ORM\OneToOne(targetEntity="Config", mappedBy="user")
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2015-02-26 08:41:42 +00:00
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
|
|
|
|
*/
|
|
|
|
private $tags;
|
|
|
|
|
2015-01-31 14:14:10 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2015-02-26 08:41:42 +00:00
|
|
|
$this->isActive = true;
|
|
|
|
$this->salt = md5(uniqid(null, true));
|
|
|
|
$this->entries = new ArrayCollection();
|
|
|
|
$this->tags = new ArrayCollection();
|
2015-01-31 14:14:10 +00:00
|
|
|
}
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2015-02-06 13:18:01 +00:00
|
|
|
/**
|
|
|
|
* @ORM\PrePersist
|
|
|
|
* @ORM\PreUpdate
|
|
|
|
*/
|
|
|
|
public function timestamps()
|
|
|
|
{
|
|
|
|
if (is_null($this->createdAt)) {
|
|
|
|
$this->createdAt = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->updatedAt = new \DateTime();
|
|
|
|
}
|
|
|
|
|
2015-01-22 16:18:56 +00:00
|
|
|
/**
|
|
|
|
* Get id
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return integer
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set username
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @param string $username
|
2015-02-06 13:18:01 +00:00
|
|
|
* @return User
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function setUsername($username)
|
|
|
|
{
|
|
|
|
$this->username = $username;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get username
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return string
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getUsername()
|
|
|
|
{
|
|
|
|
return $this->username;
|
|
|
|
}
|
|
|
|
|
2015-01-31 14:14:10 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getSalt()
|
|
|
|
{
|
|
|
|
return $this->salt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getRoles()
|
|
|
|
{
|
|
|
|
return array('ROLE_USER');
|
|
|
|
}
|
|
|
|
|
2015-01-22 16:18:56 +00:00
|
|
|
/**
|
|
|
|
* Set password
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @param string $password
|
2015-02-06 13:18:01 +00:00
|
|
|
* @return User
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function setPassword($password)
|
|
|
|
{
|
2015-02-08 20:47:36 +00:00
|
|
|
if (!$password && 0 === strlen($password)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->password = sha1($password.$this->getUsername().$this->getSalt());
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get password
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return string
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getPassword()
|
|
|
|
{
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set name
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @param string $name
|
2015-02-06 13:18:01 +00:00
|
|
|
* @return User
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get name
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return string
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set email
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @param string $email
|
2015-02-06 13:18:01 +00:00
|
|
|
* @return User
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function setEmail($email)
|
|
|
|
{
|
|
|
|
$this->email = $email;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get email
|
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return string
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getEmail()
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
2015-01-31 14:14:10 +00:00
|
|
|
|
2015-02-06 13:18:01 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCreatedAt()
|
|
|
|
{
|
|
|
|
return $this->createdAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUpdatedAt()
|
|
|
|
{
|
|
|
|
return $this->updatedAt;
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:18:54 +00:00
|
|
|
/**
|
|
|
|
* @param Entry $entry
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function addEntry(Entry $entry)
|
|
|
|
{
|
|
|
|
$this->entries[] = $entry;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ArrayCollection<Entry>
|
|
|
|
*/
|
|
|
|
public function getEntries()
|
|
|
|
{
|
|
|
|
return $this->entries;
|
|
|
|
}
|
|
|
|
|
2015-02-26 08:41:42 +00:00
|
|
|
/**
|
|
|
|
* @param Entry $entry
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function addTag(Tag $tag)
|
|
|
|
{
|
|
|
|
$this->tags[] = $tag;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ArrayCollection<Tag>
|
|
|
|
*/
|
|
|
|
public function getTags()
|
|
|
|
{
|
|
|
|
return $this->tags;
|
|
|
|
}
|
2015-01-31 14:14:10 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function eraseCredentials()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \Serializable::serialize()
|
|
|
|
*/
|
|
|
|
public function serialize()
|
|
|
|
{
|
|
|
|
return serialize(array(
|
|
|
|
$this->id,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \Serializable::unserialize()
|
|
|
|
*/
|
|
|
|
public function unserialize($serialized)
|
|
|
|
{
|
2015-01-31 18:09:34 +00:00
|
|
|
list(
|
2015-01-31 14:14:10 +00:00
|
|
|
$this->id,
|
|
|
|
) = unserialize($serialized);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isEqualTo(UserInterface $user)
|
|
|
|
{
|
|
|
|
return $this->username === $user->getUsername();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAccountNonExpired()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAccountNonLocked()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isCredentialsNonExpired()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isEnabled()
|
|
|
|
{
|
|
|
|
return $this->isActive;
|
|
|
|
}
|
2015-02-23 21:55:06 +00:00
|
|
|
/**
|
|
|
|
* Set config
|
|
|
|
*
|
|
|
|
* @param \Wallabag\CoreBundle\Entity\Config $config
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get config
|
|
|
|
*
|
|
|
|
* @return \Wallabag\CoreBundle\Entity\Config
|
|
|
|
*/
|
|
|
|
public function getConfig()
|
|
|
|
{
|
|
|
|
return $this->config;
|
|
|
|
}
|
2015-03-07 22:25:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set confirmationToken
|
|
|
|
*
|
|
|
|
* @param string $confirmationToken
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function setConfirmationToken($confirmationToken)
|
|
|
|
{
|
|
|
|
$this->confirmationToken = $confirmationToken;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get confirmationToken
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getConfirmationToken()
|
|
|
|
{
|
|
|
|
return $this->confirmationToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set passwordRequestedAt
|
|
|
|
*
|
|
|
|
* @param \DateTime $passwordRequestedAt
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function setPasswordRequestedAt($passwordRequestedAt)
|
|
|
|
{
|
|
|
|
$this->passwordRequestedAt = $passwordRequestedAt;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get passwordRequestedAt
|
|
|
|
*
|
|
|
|
* @return \DateTime
|
|
|
|
*/
|
|
|
|
public function getPasswordRequestedAt()
|
|
|
|
{
|
|
|
|
return $this->passwordRequestedAt;
|
|
|
|
}
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|