3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Symfony\Component\Security\Core\User\UserInterface
;
8 use Symfony\Component\Security\Core\User\AdvancedUserInterface
;
9 use Symfony\Component\Validator\Constraints
as Assert
;
10 use JMS\Serializer\Annotation\ExclusionPolicy
;
11 use JMS\Serializer\Annotation\Expose
;
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
18 * @ORM\HasLifecycleCallbacks()
19 * @ExclusionPolicy("all")
21 class User
implements AdvancedUserInterface
, \Serializable
27 * @ORM\Column(name="id", type="integer")
29 * @ORM\GeneratedValue(strategy="AUTO")
36 * @ORM\Column(name="username", type="text")
48 * @ORM\Column(type="string", length=32)
55 * @ORM\Column(name="password", type="text")
62 * @ORM\Column(name="name", type="text", nullable=true)
69 * @ORM\Column(name="email", type="text", nullable=false)
76 * @ORM\Column(name="is_active", type="boolean", nullable=false)
78 private $isActive = true;
81 * @ORM\Column(name="confirmation_token", type="string", nullable=true)
83 private $confirmationToken;
86 * @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
88 private $passwordRequestedAt;
93 * @ORM\Column(name="created_at", type="datetime")
100 * @ORM\Column(name="updated_at", type="datetime")
105 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
110 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
115 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
119 public function __construct()
121 $this->isActive
= true;
122 $this->salt
= md5(uniqid(null, true));
123 $this->entries
= new ArrayCollection();
124 $this->tags
= new ArrayCollection();
131 public function timestamps()
133 if (is_null($this->createdAt
)) {
134 $this->createdAt
= new \
DateTime();
137 $this->updatedAt
= new \
DateTime();
145 public function getId()
153 * @param string $username
156 public function setUsername($username)
158 $this->username
= $username;
168 public function getUsername()
170 return $this->username
;
176 public function getSalt()
184 public function getRoles()
186 return array('ROLE_USER');
192 * @param string $password
195 public function setPassword($password)
197 if (!$password && 0 === strlen($password)) {
201 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
211 public function getPassword()
213 return $this->password
;
219 * @param string $name
222 public function setName($name)
234 public function getName()
242 * @param string $email
245 public function setEmail($email)
247 $this->email
= $email;
257 public function getEmail()
265 public function getCreatedAt()
267 return $this->createdAt
;
273 public function getUpdatedAt()
275 return $this->updatedAt
;
279 * @param Entry $entry
283 public function addEntry(Entry
$entry)
285 $this->entries
[] = $entry;
291 * @return ArrayCollection<Entry>
293 public function getEntries()
295 return $this->entries
;
299 * @param Entry $entry
303 public function addTag(Tag
$tag)
305 $this->tags
[] = $tag;
311 * @return ArrayCollection<Tag>
313 public function getTags()
320 public function eraseCredentials()
325 * @see \Serializable::serialize()
327 public function serialize()
329 return serialize(array(
335 * @see \Serializable::unserialize()
337 public function unserialize($serialized)
341 ) = unserialize($serialized);
344 public function isEqualTo(UserInterface
$user)
346 return $this->username
=== $user->getUsername();
349 public function isAccountNonExpired()
354 public function isAccountNonLocked()
359 public function isCredentialsNonExpired()
364 public function isEnabled()
366 return $this->isActive
;
371 * @param \Wallabag\CoreBundle\Entity\Config $config
374 public function setConfig(\Wallabag\CoreBundle\Entity\Config
$config = null)
376 $this->config
= $config;
384 * @return \Wallabag\CoreBundle\Entity\Config
386 public function getConfig()
388 return $this->config
;
392 * Set confirmationToken
394 * @param string $confirmationToken
397 public function setConfirmationToken($confirmationToken)
399 $this->confirmationToken
= $confirmationToken;
405 * Get confirmationToken
409 public function getConfirmationToken()
411 return $this->confirmationToken
;
415 * Set passwordRequestedAt
417 * @param \DateTime $passwordRequestedAt
420 public function setPasswordRequestedAt($passwordRequestedAt)
422 $this->passwordRequestedAt
= $passwordRequestedAt;
428 * Get passwordRequestedAt
432 public function getPasswordRequestedAt()
434 return $this->passwordRequestedAt
;