Completed
Push — master ( 858bee...ca95b0 )
by Pavel
10s
created

User::getTmpPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
     * @ORM\Column(type="string", length=64, nullable=true)
56
     */
57
    private $tmpPassword;
58
59
    /**
60
     * @Assert\Length(max=4096)
61
     */
62
    private $plainPassword;
63
64
    /**
65
     * @ORM\Column(type="string", length=64)
66
     */
67
    private $role;
68
69
    /**
70
     * @ORM\Column(name="is_active", type="boolean")
71
     */
72
    private $isActive;
73
74
    /**
75
     * @var string
76
     *
77
     * @ORM\Column(name="fb_token", type="string", nullable=true)
78
     */
79
    protected $facebookToken;
80
    /**
81
     * @var string
82
     *
83
     * @ORM\Column(name="fb_id", type="string", nullable=true)
84
     */
85
    protected $facebookId;
86
    /**
87
     * @var string
88
     *
89
     * @ORM\Column(name="g_token", type="string", nullable=true)
90
     */
91
    protected $googleToken;
92
    /**
93
     * @var string
94
     *
95
     * @ORM\Column(name="g_id", type="string", nullable=true)
96
     */
97
    protected $googleId;
98
99
    /**
100
     * @ORM\Column(name="is_locked", type="boolean")
101
     */
102
    protected $isLocked;
103
104
    /**
105
     * @ORM\Column(name="hash", type="string", nullable=true)
106
     */
107
    protected $hash;
108
109
    /**
110
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\ModuleUser", mappedBy="user", cascade={"remove"})
111
     */
112
    private $modulesUser;
113
114
    /**
115
     * @ORM\Column(name="chosen_module", type="array")
116
     */
117
    private $chosenModule;
118
119
    public function jsonSerialize()
120
    {
121
        return [
122
            'id' => $this->getId(),
123
            'firstName' => $this->getFirstName(),
124
            'lastName' => $this->getLastName(),
125
            'email' => $this->getEmail()
126
        ];
127
    }
128
129 27
    public function __construct()
130
    {
131 27
        $this->isActive = false;
132 27
        $this->isLocked = false;
133 27
        $this->modulesUser = new ArrayCollection();
134 27
        $this->role = self::ROLE_USER;
135 27
        $this->chosenModule = [];
136 27
    }
137
138
    /**
139
     * @return mixed
140
     */
141
    public function getModulesUser()
142
    {
143
        return $this->modulesUser;
144
    }
145
146
    /**
147
     * @param ModuleUser $moduleUser
148
     * @return $this
149
     */
150
    public function addModuleUser(ModuleUser $moduleUser)
151
    {
152
        $this->modulesUser->add($moduleUser);
153
154
        return $this;
155
    }
156
157
    /**
158
     * @param ModuleUser $moduleUser
159
     */
160
    public function removeModuleUser(ModuleUser $moduleUser)
161
    {
162
        $this->modulesUser->removeElement($moduleUser);
163
    }
164
165
    /**
166
     * @return mixed
167
     */
168 6
    public function getId()
169
    {
170 6
        return $this->id;
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function getUsername()
177
    {
178
        return $this->getEmail();
179
    }
180
181
    /**
182
     * @return mixed
183
     */
184 4
    public function getEmail()
185
    {
186 4
        return $this->email;
187
    }
188
189
    /**
190
     * @param $email
191
     */
192 27
    public function setEmail($email)
193
    {
194 27
        $this->email = $email;
195
196 27
        return $this;
197
    }
198
199
    /**
200
     * @return mixed
201
     */
202 5
    public function getFirstName()
203
    {
204 5
        return $this->firstName;
205
    }
206
207
    /**
208
     * @param mixed $firstName
209
     */
210 27
    public function setFirstName($firstName)
211
    {
212 27
        $this->firstName = $firstName;
213
214 27
        return $this;
215
    }
216
217
    /**
218
     * @return mixed
219
     */
220 5
    public function getLastName()
221
    {
222 5
        return $this->lastName;
223
    }
224
225
    /**
226
     * @param mixed $lastName
227
     */
228 27
    public function setLastName($lastName)
229
    {
230 27
        $this->lastName = $lastName;
231
232 27
        return $this;
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238 24
    public function getPassword()
239
    {
240 24
        return $this->password;
241
    }
242
243
    /**
244
     * @param $password
245
     */
246 27
    public function setPassword($password)
247
    {
248 27
        $this->password = $password;
249 27
    }
250
251
    /**
252
     * @param $role
253
     * @return $this
254
     */
255 27
    public function setRole($role)
256
    {
257 27
        $this->role = $role;
258
259 27
        return $this;
260
    }
261
262
    /**
263
     * @return mixed
264
     */
265
    public function getRole()
266
    {
267
        return $this->role;
268
    }
269
270
    /**
271
     * Returns the roles or permissions granted to the user for security.
272
     */
273 24
    public function getRoles()
274
    {
275 24
        return [$this->role];
276
277
    }
278
279
    /**
280
     * @return mixed
281
     */
282 1
    public function getPlainPassword()
283
    {
284 1
        return $this->plainPassword;
285
    }
286
287
    /**
288
     * @param $password
289
     */
290
    public function setPlainPassword($password)
291
    {
292
        $this->plainPassword = $password;
293
    }
294
295
    /**
296
     * Returns the salt that was originally used to encode the password.
297
     */
298 27
    public function getSalt()
299
    {
300
        // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
301
        // we're using bcrypt in security.yml to encode the password, so
302
        // the salt value is built-in and you don't have to generate one
303
304 27
        return;
305
    }
306
307
    /**
308
     * Removes sensitive data from the user.
309
     */
310 24
    public function eraseCredentials()
311
    {
312
        // if you had a plainPassword property, you'd nullify it here
313
        // $this->plainPassword = null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
314 24
    }
315
316
    /**
317
     * @return bool
318
     */
319 24
    public function isAccountNonExpired()
320
    {
321 24
        return true;
322
    }
323
324
    /**
325
     * @return bool
326
     */
327 24
    public function isAccountNonLocked()
328
    {
329 24
        return $this->isLocked ? false : true ;
330
    }
331
332
    /**
333
     * @return bool
334
     */
335 24
    public function isCredentialsNonExpired()
336
    {
337 24
        return true;
338
    }
339
340
    /**
341
     * @return bool
342
     */
343 24
    public function isEnabled()
344
    {
345 24
        return $this->isActive;
346
    }
347
348
    /**
349
     * @return bool
350
     */
351
    public function getIsActive()
352
    {
353
        return $this->isActive;
354
    }
355
356
    /**
357
     * @param $active
358
     * @return mixed
359
     */
360 27
    public function setIsActive($active)
361
    {
362 27
        return $this->isActive = $active;
363
    }
364
365
    /**
366
     * @return bool
367
     */
368 2
    public function getIsLocked()
369
    {
370 2
        return $this->isLocked;
371
    }
372
373
    /**
374
     * @param $isLocked
375
     * @return mixed
376
     */
377
    public function setIsLocked($isLocked)
378
    {
379
        return $this->isLocked = $isLocked;
380
    }
381
382
    /**
383
     * @return string
384
     */
385
    public function getFacebookToken()
386
    {
387
        return $this->facebookToken;
388
    }
389
390
    /**
391
     * @param string $facebookToken
392
     * @return $this
393
     */
394
    public function setFacebookToken($facebookToken)
395
    {
396
        $this->facebookToken = $facebookToken;
397
398
        return $this;
399
    }
400
401
    /**
402
     * @return string
403
     */
404
    public function getFacebookId()
405
    {
406
        return $this->facebookId;
407
    }
408
409
    /**
410
     * @param string $facebookId
411
     * @return $this
412
     */
413
    public function setFacebookId($facebookId)
414
    {
415
        $this->facebookId = $facebookId;
416
417
        return $this;
418
    }
419
420
    /**
421
     * @return string
422
     */
423
    public function getGoogleToken()
424
    {
425
        return $this->googleToken;
426
    }
427
428
    /**
429
     * @param string $googleToken
430
     * @return $this
431
     */
432
    public function setGoogleToken($googleToken)
433
    {
434
        $this->googleToken = $googleToken;
435
436
        return $this;
437
    }
438
439
    /**
440
     * @return string
441
     */
442
    public function getGoogleId()
443
    {
444
        return $this->googleId;
445
    }
446
447
    /**
448
     * @param string $googleId
449
     * @return $this
450
     */
451
    public function setGoogleId($googleId)
452
    {
453
        $this->googleId = $googleId;
454
455
        return $this;
456
    }
457
458
    /**
459
     * @return mixed
460
     */
461
    public function getHash()
462
    {
463
        return $this->hash;
464
    }
465
466
    /**
467
     * @param mixed $hash
468
     * @return $this
469
     */
470
    public function setHash($hash)
471
    {
472
        $this->hash = $hash;
473
474
        return $this;
475
    }
476
477
    /**
478
     * @return mixed
479
     */
480
    public function getChosenModule()
481
    {
482
        return $this->chosenModule;
483
    }
484
485
    /**
486
     * @param mixed $chosenModule
487
     * @return $this
488
     */
489
    public function setChosenModule($chosenModule)
490
    {
491
        $this->chosenModule = $chosenModule;
492
493
        return $this;
494
    }
495
496
497
    public function removeChosenModule($chosenModule)
498
    {
499
        if(($key = array_search($chosenModule, $this->chosenModule)) !== false) {
500
            unset($this->chosenModule[$key]);
501
        }
502
503
        return $this;
504
    }
505
506 1
    public function getCountModules()
507
    {
508 1
        return count($this->modulesUser);
509
    }
510
511
    /**
512
     * @return mixed
513
     */
514
    public function getTmpPassword()
515
    {
516
        return $this->tmpPassword;
517
    }
518
519
    /**
520
     * @param mixed $tmpPassword
521
     * @return $this
522
     */
523
    public function setTmpPassword($tmpPassword)
524
    {
525
        $this->tmpPassword = $tmpPassword;
526
        return $this;
527
    }
528
529
}
530
531