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