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\Table(name="user")
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;
83 * @ORM\Column(name="created_at", type="datetime")
90 * @ORM\Column(name="updated_at", type="datetime")
95 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
100 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
105 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
109 public function __construct()
111 $this->isActive
= true;
112 $this->salt
= md5(uniqid(null, true));
113 $this->entries
= new ArrayCollection();
114 $this->tags
= new ArrayCollection();
121 public function timestamps()
123 if (is_null($this->createdAt
)) {
124 $this->createdAt
= new \
DateTime();
127 $this->updatedAt
= new \
DateTime();
135 public function getId()
143 * @param string $username
146 public function setUsername($username)
148 $this->username
= $username;
158 public function getUsername()
160 return $this->username
;
166 public function getSalt()
174 public function getRoles()
176 return array('ROLE_USER');
182 * @param string $password
185 public function setPassword($password)
187 if (!$password && 0 === strlen($password)) {
191 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
201 public function getPassword()
203 return $this->password
;
209 * @param string $name
212 public function setName($name)
224 public function getName()
232 * @param string $email
235 public function setEmail($email)
237 $this->email
= $email;
247 public function getEmail()
255 public function getCreatedAt()
257 return $this->createdAt
;
263 public function getUpdatedAt()
265 return $this->updatedAt
;
269 * @param Entry $entry
273 public function addEntry(Entry
$entry)
275 $this->entries
[] = $entry;
281 * @return ArrayCollection<Entry>
283 public function getEntries()
285 return $this->entries
;
289 * @param Entry $entry
293 public function addTag(Tag
$tag)
295 $this->tags
[] = $tag;
301 * @return ArrayCollection<Tag>
303 public function getTags()
310 public function eraseCredentials()
315 * @see \Serializable::serialize()
317 public function serialize()
319 return serialize(array(
325 * @see \Serializable::unserialize()
327 public function unserialize($serialized)
331 ) = unserialize($serialized);
334 public function isEqualTo(UserInterface
$user)
336 return $this->username
=== $user->getUsername();
339 public function isAccountNonExpired()
344 public function isAccountNonLocked()
349 public function isCredentialsNonExpired()
354 public function isEnabled()
356 return $this->isActive
;
361 * @param \Wallabag\CoreBundle\Entity\Config $config
364 public function setConfig(\Wallabag\CoreBundle\Entity\Config
$config = null)
366 $this->config
= $config;
374 * @return \Wallabag\CoreBundle\Entity\Config
376 public function getConfig()
378 return $this->config
;