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-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-01-22 16:18:56 +00:00
|
|
|
* @ORM\Entity
|
2015-02-06 13:18:01 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks()
|
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-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-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
|
|
|
|
*
|
|
|
|
* @ORM\Column(name="email", type="text", nullable=true)
|
|
|
|
*/
|
|
|
|
private $email;
|
|
|
|
|
2015-01-31 14:14:10 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Column(name="is_active", type="boolean")
|
|
|
|
*/
|
|
|
|
private $isActive;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
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-01-31 14:14:10 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->isActive = true;
|
2015-02-06 14:18:54 +00:00
|
|
|
$this->salt = md5(uniqid(null, true));
|
|
|
|
$this->entries = 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)
|
|
|
|
{
|
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
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-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-01-22 16:18:56 +00:00
|
|
|
}
|