]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/User.php
config for CORS
[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;
9d50517c
NL
10
11/**
2f69eb4a 12 * User
9d50517c 13 *
2f69eb4a 14 * @ORM\Table(name="user")
9d50517c 15 * @ORM\Entity
2f69eb4a 16 * @ORM\HasLifecycleCallbacks()
9d50517c 17 */
2f69eb4a 18class User implements AdvancedUserInterface, \Serializable
9d50517c
NL
19{
20 /**
21 * @var integer
22 *
2f69eb4a 23 * @ORM\Column(name="id", type="integer")
9d50517c 24 * @ORM\Id
2f69eb4a 25 * @ORM\GeneratedValue(strategy="AUTO")
9d50517c
NL
26 */
27 private $id;
28
29 /**
30 * @var string
31 *
2f69eb4a 32 * @ORM\Column(name="username", type="text")
c0d9eba0
J
33 * @Assert\NotBlank()
34 * @Assert\Length(
35 * min = "3",
36 * max = "255"
37 * )
9d50517c
NL
38 */
39 private $username;
40
c3235553 41 /**
2f69eb4a
NL
42 * @var string
43 *
c3235553
NL
44 * @ORM\Column(type="string", length=32)
45 */
46 private $salt;
47
9d50517c
NL
48 /**
49 * @var string
50 *
2f69eb4a 51 * @ORM\Column(name="password", type="text")
9d50517c
NL
52 */
53 private $password;
54
55 /**
56 * @var string
57 *
58 * @ORM\Column(name="name", type="text", nullable=true)
59 */
60 private $name;
61
62 /**
63 * @var string
64 *
c0d9eba0
J
65 * @ORM\Column(name="email", type="text", nullable=false)
66 * @Assert\Email()
67 * @Assert\NotBlank()
9d50517c
NL
68 */
69 private $email;
70
c3235553 71 /**
c0d9eba0 72 * @ORM\Column(name="is_active", type="boolean", nullable=false)
c3235553 73 */
c0d9eba0 74 private $isActive = true;
9d50517c 75
2f69eb4a
NL
76 /**
77 * @var date
78 *
79 * @ORM\Column(name="created_at", type="datetime")
80 */
81 private $createdAt;
82
83 /**
84 * @var date
85 *
86 * @ORM\Column(name="updated_at", type="datetime")
87 */
88 private $updatedAt;
89
5f09650e
NL
90 /**
91 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
92 */
93 private $entries;
94
c3235553
NL
95 public function __construct()
96 {
c0d9eba0
J
97 $this->salt = md5(uniqid(null, true));
98 $this->entries = new ArrayCollection();
c3235553 99 }
9d50517c 100
2f69eb4a
NL
101 /**
102 * @ORM\PrePersist
103 * @ORM\PreUpdate
104 */
105 public function timestamps()
106 {
107 if (is_null($this->createdAt)) {
108 $this->createdAt = new \DateTime();
109 }
110
111 $this->updatedAt = new \DateTime();
112 }
113
9d50517c
NL
114 /**
115 * Get id
116 *
7df80cb3 117 * @return integer
9d50517c
NL
118 */
119 public function getId()
120 {
121 return $this->id;
122 }
123
124 /**
125 * Set username
126 *
7df80cb3 127 * @param string $username
2f69eb4a 128 * @return User
9d50517c
NL
129 */
130 public function setUsername($username)
131 {
132 $this->username = $username;
133
134 return $this;
135 }
136
137 /**
138 * Get username
139 *
7df80cb3 140 * @return string
9d50517c
NL
141 */
142 public function getUsername()
143 {
144 return $this->username;
145 }
146
c3235553
NL
147 /**
148 * @inheritDoc
149 */
150 public function getSalt()
151 {
152 return $this->salt;
153 }
154
155 /**
156 * @inheritDoc
157 */
158 public function getRoles()
159 {
160 return array('ROLE_USER');
161 }
162
9d50517c
NL
163 /**
164 * Set password
165 *
7df80cb3 166 * @param string $password
2f69eb4a 167 * @return User
9d50517c
NL
168 */
169 public function setPassword($password)
170 {
d9169157
J
171 if (!$password && 0 === strlen($password)) {
172 return;
173 }
174
175 $this->password = sha1($password.$this->getUsername().$this->getSalt());
9d50517c
NL
176
177 return $this;
178 }
179
180 /**
181 * Get password
182 *
7df80cb3 183 * @return string
9d50517c
NL
184 */
185 public function getPassword()
186 {
187 return $this->password;
188 }
189
190 /**
191 * Set name
192 *
7df80cb3 193 * @param string $name
2f69eb4a 194 * @return User
9d50517c
NL
195 */
196 public function setName($name)
197 {
198 $this->name = $name;
199
200 return $this;
201 }
202
203 /**
204 * Get name
205 *
7df80cb3 206 * @return string
9d50517c
NL
207 */
208 public function getName()
209 {
210 return $this->name;
211 }
212
213 /**
214 * Set email
215 *
7df80cb3 216 * @param string $email
2f69eb4a 217 * @return User
9d50517c
NL
218 */
219 public function setEmail($email)
220 {
221 $this->email = $email;
222
223 return $this;
224 }
225
226 /**
227 * Get email
228 *
7df80cb3 229 * @return string
9d50517c
NL
230 */
231 public function getEmail()
232 {
233 return $this->email;
234 }
c3235553 235
2f69eb4a
NL
236 /**
237 * @return string
238 */
239 public function getCreatedAt()
240 {
241 return $this->createdAt;
242 }
243
244 /**
245 * @return string
246 */
247 public function getUpdatedAt()
248 {
249 return $this->updatedAt;
250 }
251
5f09650e
NL
252 /**
253 * @param Entry $entry
254 *
255 * @return User
256 */
257 public function addEntry(Entry $entry)
258 {
259 $this->entries[] = $entry;
260
261 return $this;
262 }
263
264 /**
265 * @return ArrayCollection<Entry>
266 */
267 public function getEntries()
268 {
269 return $this->entries;
270 }
271
c3235553
NL
272 /**
273 * @inheritDoc
274 */
275 public function eraseCredentials()
276 {
277 }
278
279 /**
280 * @see \Serializable::serialize()
281 */
282 public function serialize()
283 {
284 return serialize(array(
285 $this->id,
286 ));
287 }
288
289 /**
290 * @see \Serializable::unserialize()
291 */
292 public function unserialize($serialized)
293 {
7df80cb3 294 list(
c3235553
NL
295 $this->id,
296 ) = unserialize($serialized);
297 }
298
299 public function isEqualTo(UserInterface $user)
300 {
301 return $this->username === $user->getUsername();
302 }
303
304 public function isAccountNonExpired()
305 {
306 return true;
307 }
308
309 public function isAccountNonLocked()
310 {
311 return true;
312 }
313
314 public function isCredentialsNonExpired()
315 {
316 return true;
317 }
318
319 public function isEnabled()
320 {
321 return $this->isActive;
322 }
9d50517c 323}