aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity/User.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-08-18 11:08:45 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-09-11 20:32:37 +0200
commita1691859ca0cb4c1b360c34b05aa74bdba9e582a (patch)
tree47ef239ea8f452ba4de71f76c9cab607a4dadf8c /src/Wallabag/CoreBundle/Entity/User.php
parent9c08a891f9bb90bc3f23a575a734283c1ee00ba1 (diff)
downloadwallabag-a1691859ca0cb4c1b360c34b05aa74bdba9e582a.tar.gz
wallabag-a1691859ca0cb4c1b360c34b05aa74bdba9e582a.tar.zst
wallabag-a1691859ca0cb4c1b360c34b05aa74bdba9e582a.zip
implement FosUser
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/User.php')
-rw-r--r--src/Wallabag/CoreBundle/Entity/User.php250
1 files changed, 12 insertions, 238 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php
index 510a1594..eeae331e 100644
--- a/src/Wallabag/CoreBundle/Entity/User.php
+++ b/src/Wallabag/CoreBundle/Entity/User.php
@@ -10,6 +10,7 @@ use Symfony\Component\Security\Core\User\AdvancedUserInterface;
10use Symfony\Component\Validator\Constraints as Assert; 10use Symfony\Component\Validator\Constraints as Assert;
11use JMS\Serializer\Annotation\ExclusionPolicy; 11use JMS\Serializer\Annotation\ExclusionPolicy;
12use JMS\Serializer\Annotation\Expose; 12use JMS\Serializer\Annotation\Expose;
13use FOS\UserBundle\Model\User as BaseUser;
13 14
14/** 15/**
15 * User. 16 * User.
@@ -22,7 +23,7 @@ use JMS\Serializer\Annotation\Expose;
22 * @UniqueEntity("email") 23 * @UniqueEntity("email")
23 * @UniqueEntity("username") 24 * @UniqueEntity("username")
24 */ 25 */
25class User implements AdvancedUserInterface, \Serializable 26class User extends BaseUser implements AdvancedUserInterface, \Serializable
26{ 27{
27 /** 28 /**
28 * @var int 29 * @var int
@@ -32,100 +33,49 @@ class User implements AdvancedUserInterface, \Serializable
32 * @ORM\Id 33 * @ORM\Id
33 * @ORM\GeneratedValue(strategy="AUTO") 34 * @ORM\GeneratedValue(strategy="AUTO")
34 */ 35 */
35 private $id; 36 protected $id;
36
37 /**
38 * @var string
39 *
40 * @ORM\Column(name="username", type="text")
41 * @Assert\NotBlank()
42 * @Assert\Length(
43 * min = "3",
44 * max = "255"
45 * )
46 */
47 private $username;
48
49 /**
50 * @var string
51 *
52 * @ORM\Column(type="string", length=32)
53 */
54 private $salt;
55
56 /**
57 * @var string
58 *
59 * @ORM\Column(name="password", type="text")
60 */
61 private $password;
62 37
63 /** 38 /**
64 * @var string 39 * @var string
65 * 40 *
66 * @ORM\Column(name="name", type="text", nullable=true) 41 * @ORM\Column(name="name", type="text", nullable=true)
67 */ 42 */
68 private $name; 43 protected $name;
69
70 /**
71 * @var string
72 *
73 * @ORM\Column(name="email", type="text", nullable=false)
74 * @Assert\Email()
75 * @Assert\NotBlank()
76 */
77 private $email;
78
79 /**
80 * @ORM\Column(name="is_active", type="boolean", nullable=false)
81 */
82 private $isActive = true;
83
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 44
94 /** 45 /**
95 * @var date 46 * @var date
96 * 47 *
97 * @ORM\Column(name="created_at", type="datetime") 48 * @ORM\Column(name="created_at", type="datetime")
98 */ 49 */
99 private $createdAt; 50 protected $createdAt;
100 51
101 /** 52 /**
102 * @var date 53 * @var date
103 * 54 *
104 * @ORM\Column(name="updated_at", type="datetime") 55 * @ORM\Column(name="updated_at", type="datetime")
105 */ 56 */
106 private $updatedAt; 57 protected $updatedAt;
107 58
108 /** 59 /**
109 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"}) 60 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
110 */ 61 */
111 private $entries; 62 protected $entries;
112 63
113 /** 64 /**
114 * @ORM\OneToOne(targetEntity="Config", mappedBy="user") 65 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
115 */ 66 */
116 private $config; 67 protected $config;
117 68
118 /** 69 /**
119 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"}) 70 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
120 */ 71 */
121 private $tags; 72 protected $tags;
122 73
123 public function __construct() 74 public function __construct()
124 { 75 {
125 $this->isActive = true; 76 parent::__construct();
126 $this->salt = md5(uniqid(null, true)); 77 $this->entries = new ArrayCollection();
127 $this->entries = new ArrayCollection(); 78 $this->tags = new ArrayCollection();
128 $this->tags = new ArrayCollection();
129 } 79 }
130 80
131 /** 81 /**
@@ -142,56 +92,6 @@ class User implements AdvancedUserInterface, \Serializable
142 } 92 }
143 93
144 /** 94 /**
145 * Get id.
146 *
147 * @return int
148 */
149 public function getId()
150 {
151 return $this->id;
152 }
153
154 /**
155 * Set username.
156 *
157 * @param string $username
158 *
159 * @return User
160 */
161 public function setUsername($username)
162 {
163 $this->username = $username;
164
165 return $this;
166 }
167
168 /**
169 * Get username.
170 *
171 * @return string
172 */
173 public function getUsername()
174 {
175 return $this->username;
176 }
177
178 /**
179 * {@inheritdoc}
180 */
181 public function getSalt()
182 {
183 return $this->salt;
184 }
185
186 /**
187 * {@inheritdoc}
188 */
189 public function getRoles()
190 {
191 return array('ROLE_USER');
192 }
193
194 /**
195 * Set password. 95 * Set password.
196 * 96 *
197 * @param string $password 97 * @param string $password
@@ -210,16 +110,6 @@ class User implements AdvancedUserInterface, \Serializable
210 } 110 }
211 111
212 /** 112 /**
213 * Get password.
214 *
215 * @return string
216 */
217 public function getPassword()
218 {
219 return $this->password;
220 }
221
222 /**
223 * Set name. 113 * Set name.
224 * 114 *
225 * @param string $name 115 * @param string $name
@@ -244,30 +134,6 @@ class User implements AdvancedUserInterface, \Serializable
244 } 134 }
245 135
246 /** 136 /**
247 * Set email.
248 *
249 * @param string $email
250 *
251 * @return User
252 */
253 public function setEmail($email)
254 {
255 $this->email = $email;
256
257 return $this;
258 }
259
260 /**
261 * Get email.
262 *
263 * @return string
264 */
265 public function getEmail()
266 {
267 return $this->email;
268 }
269
270 /**
271 * @return string 137 * @return string
272 */ 138 */
273 public function getCreatedAt() 139 public function getCreatedAt()
@@ -322,56 +188,12 @@ class User implements AdvancedUserInterface, \Serializable
322 { 188 {
323 return $this->tags; 189 return $this->tags;
324 } 190 }
325 /**
326 * {@inheritdoc}
327 */
328 public function eraseCredentials()
329 {
330 }
331
332 /**
333 * @see \Serializable::serialize()
334 */
335 public function serialize()
336 {
337 return serialize(array(
338 $this->id,
339 ));
340 }
341
342 /**
343 * @see \Serializable::unserialize()
344 */
345 public function unserialize($serialized)
346 {
347 list(
348 $this->id) = unserialize($serialized);
349 }
350 191
351 public function isEqualTo(UserInterface $user) 192 public function isEqualTo(UserInterface $user)
352 { 193 {
353 return $this->username === $user->getUsername(); 194 return $this->username === $user->getUsername();
354 } 195 }
355 196
356 public function isAccountNonExpired()
357 {
358 return true;
359 }
360
361 public function isAccountNonLocked()
362 {
363 return true;
364 }
365
366 public function isCredentialsNonExpired()
367 {
368 return true;
369 }
370
371 public function isEnabled()
372 {
373 return $this->isActive;
374 }
375 /** 197 /**
376 * Set config. 198 * Set config.
377 * 199 *
@@ -395,52 +217,4 @@ class User implements AdvancedUserInterface, \Serializable
395 { 217 {
396 return $this->config; 218 return $this->config;
397 } 219 }
398
399 /**
400 * Set confirmationToken.
401 *
402 * @param string $confirmationToken
403 *
404 * @return User
405 */
406 public function setConfirmationToken($confirmationToken)
407 {
408 $this->confirmationToken = $confirmationToken;
409
410 return $this;
411 }
412
413 /**
414 * Get confirmationToken.
415 *
416 * @return string
417 */
418 public function getConfirmationToken()
419 {
420 return $this->confirmationToken;
421 }
422
423 /**
424 * Set passwordRequestedAt.
425 *
426 * @param \DateTime $passwordRequestedAt
427 *
428 * @return User
429 */
430 public function setPasswordRequestedAt($passwordRequestedAt)
431 {
432 $this->passwordRequestedAt = $passwordRequestedAt;
433
434 return $this;
435 }
436
437 /**
438 * Get passwordRequestedAt.
439 *
440 * @return \DateTime
441 */
442 public function getPasswordRequestedAt()
443 {
444 return $this->passwordRequestedAt;
445 }
446} 220}