wallabag/src/Wallabag/CoreBundle/Entity/User.php

447 lines
7.8 KiB
PHP
Raw Normal View History

2015-01-22 16:18:56 +00:00
<?php
namespace Wallabag\CoreBundle\Entity;
2015-01-22 16:18:56 +00:00
use Doctrine\Common\Collections\ArrayCollection;
2015-01-22 16:18:56 +00:00
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2015-01-31 14:14:10 +00:00
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
2015-01-22 16:18:56 +00:00
/**
2015-05-30 11:52:26 +00:00
* User.
2015-01-22 16:18:56 +00:00
*
2015-03-28 13:27:45 +00:00
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
2015-03-28 10:29:19 +00:00
* @ORM\Table
2015-02-06 13:18:01 +00:00
* @ORM\HasLifecycleCallbacks()
* @ExclusionPolicy("all")
*
* @UniqueEntity("email")
* @UniqueEntity("username")
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
{
/**
2015-05-30 11:52:26 +00:00
* @var int
2015-01-22 16:18:56 +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")
* @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
*
* @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
/**
* @ORM\Column(name="is_active", type="boolean", nullable=false)
2015-01-31 14:14:10 +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;
/**
* @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
*/
private $entries;
/**
* @ORM\OneToOne(targetEntity="Config", mappedBy="user")
*/
private $config;
/**
* @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
*/
private $tags;
2015-01-31 14:14:10 +00:00
public function __construct()
{
$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
/**
2015-05-30 11:52:26 +00:00
* Get id.
2015-01-22 16:18:56 +00:00
*
2015-05-30 11:52:26 +00:00
* @return int
2015-01-22 16:18:56 +00:00
*/
public function getId()
{
return $this->id;
}
/**
2015-05-30 11:52:26 +00:00
* Set username.
*
* @param string $username
2015-01-22 16:18:56 +00:00
*
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;
}
/**
2015-05-30 11:52:26 +00:00
* Get username.
2015-01-22 16:18:56 +00:00
*
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}
2015-01-31 14:14:10 +00:00
*/
public function getSalt()
{
return $this->salt;
}
/**
* {@inheritdoc}
2015-01-31 14:14:10 +00:00
*/
public function getRoles()
{
return array('ROLE_USER');
}
2015-01-22 16:18:56 +00:00
/**
2015-05-30 11:52:26 +00:00
* Set password.
*
* @param string $password
2015-01-22 16:18:56 +00:00
*
2015-02-06 13:18:01 +00:00
* @return User
2015-01-22 16:18:56 +00:00
*/
public function setPassword($password)
{
if (!$password && 0 === strlen($password)) {
return;
}
$this->password = sha1($password.$this->getUsername().$this->getSalt());
2015-01-22 16:18:56 +00:00
return $this;
}
/**
2015-05-30 11:52:26 +00:00
* Get password.
2015-01-22 16:18:56 +00:00
*
2015-01-31 18:09:34 +00:00
* @return string
2015-01-22 16:18:56 +00:00
*/
public function getPassword()
{
return $this->password;
}
/**
2015-05-30 11:52:26 +00:00
* Set name.
*
* @param string $name
2015-01-22 16:18:56 +00:00
*
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;
}
/**
2015-05-30 11:52:26 +00:00
* Get name.
2015-01-22 16:18:56 +00:00
*
2015-01-31 18:09:34 +00:00
* @return string
2015-01-22 16:18:56 +00:00
*/
public function getName()
{
return $this->name;
}
/**
2015-05-30 11:52:26 +00:00
* Set email.
*
* @param string $email
2015-01-22 16:18:56 +00:00
*
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;
}
/**
2015-05-30 11:52:26 +00:00
* Get email.
2015-01-22 16:18:56 +00:00
*
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;
}
/**
* @param Entry $entry
*
* @return User
*/
public function addEntry(Entry $entry)
{
$this->entries[] = $entry;
return $this;
}
/**
* @return ArrayCollection<Entry>
*/
public function getEntries()
{
return $this->entries;
}
/**
* @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}
2015-01-31 14:14:10 +00:00
*/
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-05-30 11:52:26 +00:00
$this->id) = unserialize($serialized);
2015-01-31 14:14:10 +00:00
}
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-05-30 11:52:26 +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;
}
/**
2015-05-30 11:52:26 +00:00
* Get config.
*
* @return \Wallabag\CoreBundle\Entity\Config
*/
public function getConfig()
{
return $this->config;
}
2015-03-07 22:25:36 +00:00
/**
2015-05-30 11:52:26 +00:00
* Set confirmationToken.
*
* @param string $confirmationToken
2015-03-07 22:25:36 +00:00
*
* @return User
*/
public function setConfirmationToken($confirmationToken)
{
$this->confirmationToken = $confirmationToken;
return $this;
}
/**
2015-05-30 11:52:26 +00:00
* Get confirmationToken.
2015-03-07 22:25:36 +00:00
*
* @return string
*/
public function getConfirmationToken()
{
return $this->confirmationToken;
}
/**
2015-05-30 11:52:26 +00:00
* Set passwordRequestedAt.
*
* @param \DateTime $passwordRequestedAt
2015-03-07 22:25:36 +00:00
*
* @return User
*/
public function setPasswordRequestedAt($passwordRequestedAt)
{
$this->passwordRequestedAt = $passwordRequestedAt;
return $this;
}
/**
2015-05-30 11:52:26 +00:00
* Get passwordRequestedAt.
2015-03-07 22:25:36 +00:00
*
* @return \DateTime
*/
public function getPasswordRequestedAt()
{
return $this->passwordRequestedAt;
}
2015-01-22 16:18:56 +00:00
}