]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/User.php
Update deps
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / User.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Entity;
9d50517c 4
5f09650e 5use Doctrine\Common\Collections\ArrayCollection;
9d50517c 6use Doctrine\ORM\Mapping as ORM;
c844dc0c 7use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
c3235553 8use Symfony\Component\Security\Core\User\UserInterface;
c3235553 9use Symfony\Component\Security\Core\User\AdvancedUserInterface;
c0d9eba0 10use Symfony\Component\Validator\Constraints as Assert;
0f006880
NL
11use JMS\Serializer\Annotation\ExclusionPolicy;
12use JMS\Serializer\Annotation\Expose;
9d50517c
NL
13
14/**
2f69eb4a 15 * User
9d50517c 16 *
0c83fd59 17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
164bd801 18 * @ORM\Table
2f69eb4a 19 * @ORM\HasLifecycleCallbacks()
0f006880 20 * @ExclusionPolicy("all")
c844dc0c
J
21 *
22 * @UniqueEntity("email")
23 * @UniqueEntity("username")
9d50517c 24 */
2f69eb4a 25class User implements AdvancedUserInterface, \Serializable
9d50517c
NL
26{
27 /**
28 * @var integer
29 *
0f006880 30 * @Expose
2f69eb4a 31 * @ORM\Column(name="id", type="integer")
9d50517c 32 * @ORM\Id
2f69eb4a 33 * @ORM\GeneratedValue(strategy="AUTO")
9d50517c
NL
34 */
35 private $id;
36
37 /**
38 * @var string
39 *
2f69eb4a 40 * @ORM\Column(name="username", type="text")
c0d9eba0
J
41 * @Assert\NotBlank()
42 * @Assert\Length(
43 * min = "3",
44 * max = "255"
45 * )
9d50517c
NL
46 */
47 private $username;
48
c3235553 49 /**
2f69eb4a
NL
50 * @var string
51 *
c3235553
NL
52 * @ORM\Column(type="string", length=32)
53 */
54 private $salt;
55
9d50517c
NL
56 /**
57 * @var string
58 *
2f69eb4a 59 * @ORM\Column(name="password", type="text")
9d50517c
NL
60 */
61 private $password;
62
63 /**
64 * @var string
65 *
66 * @ORM\Column(name="name", type="text", nullable=true)
67 */
68 private $name;
69
70 /**
71 * @var string
72 *
c0d9eba0
J
73 * @ORM\Column(name="email", type="text", nullable=false)
74 * @Assert\Email()
75 * @Assert\NotBlank()
9d50517c
NL
76 */
77 private $email;
78
c3235553 79 /**
c0d9eba0 80 * @ORM\Column(name="is_active", type="boolean", nullable=false)
c3235553 81 */
c0d9eba0 82 private $isActive = true;
9d50517c 83
6894d48e
J
84 /**
85 * @ORM\Column(name="confirmation_token", type="string", nullable=true)
86 */
87 private $confirmationToken;
88
89 /**
90 * @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
91 */
92 private $passwordRequestedAt;
93
2f69eb4a
NL
94 /**
95 * @var date
96 *
97 * @ORM\Column(name="created_at", type="datetime")
98 */
99 private $createdAt;
100
101 /**
102 * @var date
103 *
104 * @ORM\Column(name="updated_at", type="datetime")
105 */
106 private $updatedAt;
107
5f09650e
NL
108 /**
109 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
110 */
111 private $entries;
112
32da2a70
J
113 /**
114 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
115 */
116 private $config;
117
092ca707
NL
118 /**
119 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
120 */
121 private $tags;
122
c3235553
NL
123 public function __construct()
124 {
092ca707
NL
125 $this->isActive = true;
126 $this->salt = md5(uniqid(null, true));
127 $this->entries = new ArrayCollection();
128 $this->tags = new ArrayCollection();
c3235553 129 }
9d50517c 130
2f69eb4a
NL
131 /**
132 * @ORM\PrePersist
133 * @ORM\PreUpdate
134 */
135 public function timestamps()
136 {
137 if (is_null($this->createdAt)) {
138 $this->createdAt = new \DateTime();
139 }
140
141 $this->updatedAt = new \DateTime();
142 }
143
9d50517c
NL
144 /**
145 * Get id
146 *
7df80cb3 147 * @return integer
9d50517c
NL
148 */
149 public function getId()
150 {
151 return $this->id;
152 }
153
154 /**
155 * Set username
156 *
7df80cb3 157 * @param string $username
2f69eb4a 158 * @return User
9d50517c
NL
159 */
160 public function setUsername($username)
161 {
162 $this->username = $username;
163
164 return $this;
165 }
166
167 /**
168 * Get username
169 *
7df80cb3 170 * @return string
9d50517c
NL
171 */
172 public function getUsername()
173 {
174 return $this->username;
175 }
176
c3235553
NL
177 /**
178 * @inheritDoc
179 */
180 public function getSalt()
181 {
182 return $this->salt;
183 }
184
185 /**
186 * @inheritDoc
187 */
188 public function getRoles()
189 {
190 return array('ROLE_USER');
191 }
192
9d50517c
NL
193 /**
194 * Set password
195 *
7df80cb3 196 * @param string $password
2f69eb4a 197 * @return User
9d50517c
NL
198 */
199 public function setPassword($password)
200 {
d9169157
J
201 if (!$password && 0 === strlen($password)) {
202 return;
203 }
204
205 $this->password = sha1($password.$this->getUsername().$this->getSalt());
9d50517c
NL
206
207 return $this;
208 }
209
210 /**
211 * Get password
212 *
7df80cb3 213 * @return string
9d50517c
NL
214 */
215 public function getPassword()
216 {
217 return $this->password;
218 }
219
220 /**
221 * Set name
222 *
7df80cb3 223 * @param string $name
2f69eb4a 224 * @return User
9d50517c
NL
225 */
226 public function setName($name)
227 {
228 $this->name = $name;
229
230 return $this;
231 }
232
233 /**
234 * Get name
235 *
7df80cb3 236 * @return string
9d50517c
NL
237 */
238 public function getName()
239 {
240 return $this->name;
241 }
242
243 /**
244 * Set email
245 *
7df80cb3 246 * @param string $email
2f69eb4a 247 * @return User
9d50517c
NL
248 */
249 public function setEmail($email)
250 {
251 $this->email = $email;
252
253 return $this;
254 }
255
256 /**
257 * Get email
258 *
7df80cb3 259 * @return string
9d50517c
NL
260 */
261 public function getEmail()
262 {
263 return $this->email;
264 }
c3235553 265
2f69eb4a
NL
266 /**
267 * @return string
268 */
269 public function getCreatedAt()
270 {
271 return $this->createdAt;
272 }
273
274 /**
275 * @return string
276 */
277 public function getUpdatedAt()
278 {
279 return $this->updatedAt;
280 }
281
5f09650e
NL
282 /**
283 * @param Entry $entry
284 *
285 * @return User
286 */
287 public function addEntry(Entry $entry)
288 {
289 $this->entries[] = $entry;
290
291 return $this;
292 }
293
294 /**
295 * @return ArrayCollection<Entry>
296 */
297 public function getEntries()
298 {
299 return $this->entries;
300 }
301
092ca707
NL
302 /**
303 * @param Entry $entry
304 *
305 * @return User
306 */
307 public function addTag(Tag $tag)
308 {
309 $this->tags[] = $tag;
310
311 return $this;
312 }
313
314 /**
315 * @return ArrayCollection<Tag>
316 */
317 public function getTags()
318 {
319 return $this->tags;
320 }
c3235553
NL
321 /**
322 * @inheritDoc
323 */
324 public function eraseCredentials()
325 {
326 }
327
328 /**
329 * @see \Serializable::serialize()
330 */
331 public function serialize()
332 {
333 return serialize(array(
334 $this->id,
335 ));
336 }
337
338 /**
339 * @see \Serializable::unserialize()
340 */
341 public function unserialize($serialized)
342 {
7df80cb3 343 list(
c3235553
NL
344 $this->id,
345 ) = unserialize($serialized);
346 }
347
348 public function isEqualTo(UserInterface $user)
349 {
350 return $this->username === $user->getUsername();
351 }
352
353 public function isAccountNonExpired()
354 {
355 return true;
356 }
357
358 public function isAccountNonLocked()
359 {
360 return true;
361 }
362
363 public function isCredentialsNonExpired()
364 {
365 return true;
366 }
367
368 public function isEnabled()
369 {
370 return $this->isActive;
371 }
32da2a70
J
372 /**
373 * Set config
374 *
375 * @param \Wallabag\CoreBundle\Entity\Config $config
376 * @return User
377 */
378 public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
379 {
380 $this->config = $config;
381
382 return $this;
383 }
384
385 /**
386 * Get config
387 *
388 * @return \Wallabag\CoreBundle\Entity\Config
389 */
390 public function getConfig()
391 {
392 return $this->config;
393 }
6894d48e
J
394
395 /**
396 * Set confirmationToken
397 *
398 * @param string $confirmationToken
399 * @return User
400 */
401 public function setConfirmationToken($confirmationToken)
402 {
403 $this->confirmationToken = $confirmationToken;
404
405 return $this;
406 }
407
408 /**
409 * Get confirmationToken
410 *
411 * @return string
412 */
413 public function getConfirmationToken()
414 {
415 return $this->confirmationToken;
416 }
417
418 /**
419 * Set passwordRequestedAt
420 *
421 * @param \DateTime $passwordRequestedAt
422 * @return User
423 */
424 public function setPasswordRequestedAt($passwordRequestedAt)
425 {
426 $this->passwordRequestedAt = $passwordRequestedAt;
427
428 return $this;
429 }
430
431 /**
432 * Get passwordRequestedAt
433 *
434 * @return \DateTime
435 */
436 public function getPasswordRequestedAt()
437 {
438 return $this->passwordRequestedAt;
439 }
9d50517c 440}