3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
8 use Symfony\Component\Security\Core\User\UserInterface
;
9 use Symfony\Component\Security\Core\User\AdvancedUserInterface
;
10 use Symfony\Component\Validator\Constraints
as Assert
;
11 use JMS\Serializer\Annotation\ExclusionPolicy
;
12 use JMS\Serializer\Annotation\Expose
;
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
19 * @ORM\HasLifecycleCallbacks()
20 * @ExclusionPolicy("all")
22 * @UniqueEntity("email")
23 * @UniqueEntity("username")
25 class User
implements AdvancedUserInterface
, \Serializable
31 * @ORM\Column(name="id", type="integer")
33 * @ORM\GeneratedValue(strategy="AUTO")
40 * @ORM\Column(name="username", type="text")
52 * @ORM\Column(type="string", length=32)
59 * @ORM\Column(name="password", type="text")
66 * @ORM\Column(name="name", type="text", nullable=true)
73 * @ORM\Column(name="email", type="text", nullable=false)
80 * @ORM\Column(name="is_active", type="boolean", nullable=false)
82 private $isActive = true;
85 * @ORM\Column(name="confirmation_token", type="string", nullable=true)
87 private $confirmationToken;
90 * @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
92 private $passwordRequestedAt;
97 * @ORM\Column(name="created_at", type="datetime")
104 * @ORM\Column(name="updated_at", type="datetime")
109 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
114 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
119 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
123 public function __construct()
125 $this->isActive
= true;
126 $this->salt
= md5(uniqid(null, true));
127 $this->entries
= new ArrayCollection();
128 $this->tags
= new ArrayCollection();
135 public function timestamps()
137 if (is_null($this->createdAt
)) {
138 $this->createdAt
= new \
DateTime();
141 $this->updatedAt
= new \
DateTime();
149 public function getId()
157 * @param string $username
161 public function setUsername($username)
163 $this->username
= $username;
173 public function getUsername()
175 return $this->username
;
181 public function getSalt()
189 public function getRoles()
191 return array('ROLE_USER');
197 * @param string $password
201 public function setPassword($password)
203 if (!$password && 0 === strlen($password)) {
207 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
217 public function getPassword()
219 return $this->password
;
225 * @param string $name
229 public function setName($name)
241 public function getName()
249 * @param string $email
253 public function setEmail($email)
255 $this->email
= $email;
265 public function getEmail()
273 public function getCreatedAt()
275 return $this->createdAt
;
281 public function getUpdatedAt()
283 return $this->updatedAt
;
287 * @param Entry $entry
291 public function addEntry(Entry
$entry)
293 $this->entries
[] = $entry;
299 * @return ArrayCollection<Entry>
301 public function getEntries()
303 return $this->entries
;
307 * @param Entry $entry
311 public function addTag(Tag
$tag)
313 $this->tags
[] = $tag;
319 * @return ArrayCollection<Tag>
321 public function getTags()
328 public function eraseCredentials()
333 * @see \Serializable::serialize()
335 public function serialize()
337 return serialize(array(
343 * @see \Serializable::unserialize()
345 public function unserialize($serialized)
348 $this->id
) = unserialize($serialized);
351 public function isEqualTo(UserInterface
$user)
353 return $this->username
=== $user->getUsername();
356 public function isAccountNonExpired()
361 public function isAccountNonLocked()
366 public function isCredentialsNonExpired()
371 public function isEnabled()
373 return $this->isActive
;
378 * @param \Wallabag\CoreBundle\Entity\Config $config
382 public function setConfig(\Wallabag\CoreBundle\Entity\Config
$config = null)
384 $this->config
= $config;
392 * @return \Wallabag\CoreBundle\Entity\Config
394 public function getConfig()
396 return $this->config
;
400 * Set confirmationToken.
402 * @param string $confirmationToken
406 public function setConfirmationToken($confirmationToken)
408 $this->confirmationToken
= $confirmationToken;
414 * Get confirmationToken.
418 public function getConfirmationToken()
420 return $this->confirmationToken
;
424 * Set passwordRequestedAt.
426 * @param \DateTime $passwordRequestedAt
430 public function setPasswordRequestedAt($passwordRequestedAt)
432 $this->passwordRequestedAt
= $passwordRequestedAt;
438 * Get passwordRequestedAt.
442 public function getPasswordRequestedAt()
444 return $this->passwordRequestedAt
;