1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
8
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
9
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* User |
13
|
|
|
* |
14
|
|
|
* @ORM\Table(name="user") |
15
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") |
16
|
|
|
* @UniqueEntity(fields="email", message="Email already taken") |
17
|
|
|
*/ |
18
|
|
|
class User implements AdvancedUserInterface, \JsonSerializable |
19
|
|
|
{ |
20
|
|
|
const ROLE_ADMIN = 'ROLE_ADMIN'; |
21
|
|
|
const ROLE_USER = 'ROLE_USER'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Id |
25
|
|
|
* @ORM\GeneratedValue |
26
|
|
|
* @ORM\Column(type="integer") |
27
|
|
|
*/ |
28
|
|
|
private $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\Column(type="string", unique=true) |
32
|
|
|
* @Assert\NotBlank() |
33
|
|
|
* @Assert\Email() |
34
|
|
|
*/ |
35
|
|
|
private $email; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\Column(type="string", length=40) |
39
|
|
|
* @Assert\Length(min="1", minMessage="This field can not be less than 1 character") |
40
|
|
|
*/ |
41
|
|
|
private $firstName; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @ORM\Column(type="string", length=40) |
45
|
|
|
* @Assert\Length(min="1", minMessage="This field can not be less than 1 character") |
46
|
|
|
*/ |
47
|
|
|
private $lastName; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @ORM\Column(type="string", length=64, nullable=true) |
51
|
|
|
*/ |
52
|
|
|
private $password; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Assert\Length(max=4096) |
56
|
|
|
*/ |
57
|
|
|
private $plainPassword; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @ORM\Column(type="string", length=64) |
61
|
|
|
*/ |
62
|
|
|
private $role; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
66
|
|
|
*/ |
67
|
|
|
private $isActive; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
* |
72
|
|
|
* @ORM\Column(name="fb_token", type="string", nullable=true) |
73
|
|
|
*/ |
74
|
|
|
protected $facebookToken; |
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
* |
78
|
|
|
* @ORM\Column(name="fb_id", type="string", nullable=true) |
79
|
|
|
*/ |
80
|
|
|
protected $facebookId; |
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="g_token", type="string", nullable=true) |
85
|
|
|
*/ |
86
|
|
|
protected $googleToken; |
87
|
|
|
/** |
88
|
|
|
* @var string |
89
|
|
|
* |
90
|
|
|
* @ORM\Column(name="g_id", type="string", nullable=true) |
91
|
|
|
*/ |
92
|
|
|
protected $googleId; |
93
|
|
|
/** |
94
|
|
|
* @var string |
95
|
|
|
* |
96
|
|
|
* @ORM\Column(name="type", type="string", nullable=true) |
97
|
|
|
*/ |
98
|
|
|
protected $type; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @ORM\Column(name="is_locked", type="boolean") |
102
|
|
|
*/ |
103
|
|
|
protected $isLocked; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @ORM\Column(name="hash", type="string", nullable=true) |
107
|
|
|
*/ |
108
|
|
|
protected $hash; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ModuleUser", mappedBy="user") |
112
|
|
|
*/ |
113
|
|
|
private $modulesUser; |
114
|
|
|
|
115
|
|
|
public function jsonSerialize() |
116
|
|
|
{ |
117
|
|
|
return [ |
118
|
|
|
'firstName' => $this->getFirstName(), |
119
|
|
|
'lastName' => $this->getLastName(), |
120
|
|
|
'email' => $this->getEmail() |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
27 |
|
public function __construct() |
125
|
|
|
{ |
126
|
27 |
|
$this->isActive = false; |
127
|
27 |
|
$this->isLocked = false; |
128
|
27 |
|
$this->modulesUser = new ArrayCollection(); |
129
|
27 |
|
$this->role = self::ROLE_USER; |
130
|
27 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function getModulesUser() |
136
|
|
|
{ |
137
|
|
|
return $this->modulesUser; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param ModuleUser $moduleUser |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function addModuleUser(ModuleUser $moduleUser) |
145
|
|
|
{ |
146
|
|
|
$this->modulesUser->add($moduleUser); |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param ModuleUser $moduleUser |
153
|
|
|
*/ |
154
|
|
|
public function removeModuleUser(ModuleUser $moduleUser) |
155
|
|
|
{ |
156
|
|
|
$this->modulesUser->removeElement($moduleUser); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return mixed |
161
|
|
|
*/ |
162
|
6 |
|
public function getId() |
163
|
|
|
{ |
164
|
6 |
|
return $this->id; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
*/ |
170
|
|
|
public function getUsername() |
171
|
|
|
{ |
172
|
|
|
return $this->getEmail(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return mixed |
177
|
|
|
*/ |
178
|
3 |
|
public function getEmail() |
179
|
|
|
{ |
180
|
3 |
|
return $this->email; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param $email |
185
|
|
|
*/ |
186
|
27 |
|
public function setEmail($email) |
187
|
|
|
{ |
188
|
27 |
|
$this->email = $email; |
189
|
|
|
|
190
|
27 |
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return mixed |
195
|
|
|
*/ |
196
|
5 |
|
public function getFirstName() |
197
|
|
|
{ |
198
|
5 |
|
return $this->firstName; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param mixed $firstName |
203
|
|
|
*/ |
204
|
27 |
|
public function setFirstName($firstName) |
205
|
|
|
{ |
206
|
27 |
|
$this->firstName = $firstName; |
207
|
|
|
|
208
|
27 |
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return mixed |
213
|
|
|
*/ |
214
|
5 |
|
public function getLastName() |
215
|
|
|
{ |
216
|
5 |
|
return $this->lastName; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param mixed $lastName |
221
|
|
|
*/ |
222
|
27 |
|
public function setLastName($lastName) |
223
|
|
|
{ |
224
|
27 |
|
$this->lastName = $lastName; |
225
|
|
|
|
226
|
27 |
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* {@inheritdoc} |
231
|
|
|
*/ |
232
|
24 |
|
public function getPassword() |
233
|
|
|
{ |
234
|
24 |
|
return $this->password; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param $password |
239
|
|
|
*/ |
240
|
27 |
|
public function setPassword($password) |
241
|
|
|
{ |
242
|
27 |
|
$this->password = $password; |
243
|
27 |
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param $role |
247
|
|
|
* @return $this |
248
|
|
|
*/ |
249
|
27 |
|
public function setRole($role) |
250
|
|
|
{ |
251
|
27 |
|
$this->role = $role; |
252
|
|
|
|
253
|
27 |
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return mixed |
258
|
|
|
*/ |
259
|
|
|
public function getRole() |
260
|
|
|
{ |
261
|
|
|
return $this->role; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Returns the roles or permissions granted to the user for security. |
266
|
|
|
*/ |
267
|
24 |
|
public function getRoles() |
268
|
|
|
{ |
269
|
24 |
|
return [$this->role]; |
270
|
|
|
|
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return mixed |
275
|
|
|
*/ |
276
|
1 |
|
public function getPlainPassword() |
277
|
|
|
{ |
278
|
1 |
|
return $this->plainPassword; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @param $password |
283
|
|
|
*/ |
284
|
|
|
public function setPlainPassword($password) |
285
|
|
|
{ |
286
|
|
|
$this->plainPassword = $password; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Returns the salt that was originally used to encode the password. |
291
|
|
|
*/ |
292
|
27 |
|
public function getSalt() |
293
|
|
|
{ |
294
|
|
|
// See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html |
295
|
|
|
// we're using bcrypt in security.yml to encode the password, so |
296
|
|
|
// the salt value is built-in and you don't have to generate one |
297
|
|
|
|
298
|
27 |
|
return; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Removes sensitive data from the user. |
303
|
|
|
*/ |
304
|
24 |
|
public function eraseCredentials() |
305
|
|
|
{ |
306
|
|
|
// if you had a plainPassword property, you'd nullify it here |
307
|
|
|
// $this->plainPassword = null; |
|
|
|
|
308
|
24 |
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return bool |
312
|
|
|
*/ |
313
|
24 |
|
public function isAccountNonExpired() |
314
|
|
|
{ |
315
|
24 |
|
return true; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return bool |
320
|
|
|
*/ |
321
|
24 |
|
public function isAccountNonLocked() |
322
|
|
|
{ |
323
|
24 |
|
return $this->isLocked ? false : true ; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return bool |
328
|
|
|
*/ |
329
|
24 |
|
public function isCredentialsNonExpired() |
330
|
|
|
{ |
331
|
24 |
|
return true; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @return bool |
336
|
|
|
*/ |
337
|
24 |
|
public function isEnabled() |
338
|
|
|
{ |
339
|
24 |
|
return $this->isActive; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @return bool |
344
|
|
|
*/ |
345
|
|
|
public function getIsActive() |
346
|
|
|
{ |
347
|
|
|
return $this->isActive; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @param $active |
352
|
|
|
* @return mixed |
353
|
|
|
*/ |
354
|
27 |
|
public function setIsActive($active) |
355
|
|
|
{ |
356
|
27 |
|
return $this->isActive = $active; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @return bool |
361
|
|
|
*/ |
362
|
2 |
|
public function getIsLocked() |
363
|
|
|
{ |
364
|
2 |
|
return $this->isLocked; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param $isLocked |
369
|
|
|
* @return mixed |
370
|
|
|
*/ |
371
|
|
|
public function setIsLocked($isLocked) |
372
|
|
|
{ |
373
|
|
|
return $this->isLocked = $isLocked; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @return string |
378
|
|
|
*/ |
379
|
|
|
public function getFacebookToken() |
380
|
|
|
{ |
381
|
|
|
return $this->facebookToken; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @param string $facebookToken |
386
|
|
|
* @return $this |
387
|
|
|
*/ |
388
|
|
|
public function setFacebookToken($facebookToken) |
389
|
|
|
{ |
390
|
|
|
$this->facebookToken = $facebookToken; |
391
|
|
|
|
392
|
|
|
return $this; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @return string |
397
|
|
|
*/ |
398
|
|
|
public function getFacebookId() |
399
|
|
|
{ |
400
|
|
|
return $this->facebookId; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @param string $facebookId |
405
|
|
|
* @return $this |
406
|
|
|
*/ |
407
|
|
|
public function setFacebookId($facebookId) |
408
|
|
|
{ |
409
|
|
|
$this->facebookId = $facebookId; |
410
|
|
|
|
411
|
|
|
return $this; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @return string |
416
|
|
|
*/ |
417
|
|
|
public function getGoogleToken() |
418
|
|
|
{ |
419
|
|
|
return $this->googleToken; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @param string $googleToken |
424
|
|
|
* @return $this |
425
|
|
|
*/ |
426
|
|
|
public function setGoogleToken($googleToken) |
427
|
|
|
{ |
428
|
|
|
$this->googleToken = $googleToken; |
429
|
|
|
|
430
|
|
|
return $this; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @return string |
435
|
|
|
*/ |
436
|
|
|
public function getGoogleId() |
437
|
|
|
{ |
438
|
|
|
return $this->googleId; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* @param string $googleId |
443
|
|
|
* @return $this |
444
|
|
|
*/ |
445
|
|
|
public function setGoogleId($googleId) |
446
|
|
|
{ |
447
|
|
|
$this->googleId = $googleId; |
448
|
|
|
|
449
|
|
|
return $this; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Set type |
455
|
|
|
* |
456
|
|
|
* @param string $type |
457
|
|
|
* @return User |
458
|
|
|
*/ |
459
|
|
|
public function setType($type) |
460
|
|
|
{ |
461
|
|
|
$this->type = $type; |
462
|
|
|
|
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Get type |
468
|
|
|
* |
469
|
|
|
* @return string |
470
|
|
|
*/ |
471
|
|
|
public function getType() |
472
|
|
|
{ |
473
|
|
|
return $this->type; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @return mixed |
478
|
|
|
*/ |
479
|
|
|
public function getHash() |
480
|
|
|
{ |
481
|
|
|
return $this->hash; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @param mixed $hash |
486
|
|
|
* @return $this |
487
|
|
|
*/ |
488
|
|
|
public function setHash($hash) |
489
|
|
|
{ |
490
|
|
|
$this->hash = $hash; |
491
|
|
|
|
492
|
|
|
return $this; |
493
|
|
|
} |
494
|
|
|
|
495
|
1 |
|
public function getCountModules() |
496
|
|
|
{ |
497
|
1 |
|
return count($this->modulesUser); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.