Completed
Push — develop ( c0e59c...ad429f )
by Marek
02:45
created

User::setMailCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace AppBundle\Entity;
3
4
use DateTime;
5
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
6
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
7
8
/**
9
 * User
10
 */
11
class User extends AbstractEntity implements AdvancedUserInterface, EncoderAwareInterface, \Serializable
12
{
13
    const ENCODER_BCRYPT    = 'bcrypt';
14
    const ENCODER_MD5       = 'md5';
15
    const ENCODER_SHA       = 'salted_sha';
16
17
    //region Column properties
18
19
    /**
20
     * @var integer
21
     */
22
    protected $id;
23
24
    /**
25
     * @var string
26
     */
27
    protected $login;
28
29
    /**
30
     * @var string
31
     */
32
    protected $password;
33
34
    /**
35
     * @var string
36
     */
37
    protected $email;
38
39
    /**
40
     * @var DateTime
41
     */
42
    protected $lastAction = 'CURRENT_TIMESTAMP';
43
44
    /**
45
     * @var string
46
     */
47
    protected $userAction;
48
49
    /**
50
     * @var integer
51
     */
52
    protected $userActionId;
53
54
    /**
55
     * @var string
56
     */
57
    protected $locationVector;
58
59
    /**
60
     * @var integer
61
     */
62
    protected $mailCount = 0;
63
64
    /**
65
     * @var integer
66
     */
67
    protected $userMailId;
68
69
    /**
70
     * @var integer
71
     */
72
    protected $k;
73
74
    /**
75
     * @var integer
76
     */
77
    protected $kWallet = 0;
78
79
    /**
80
     * @var integer
81
     */
82
    protected $listingAmount = 32;
83
84
    /**
85
     * @var string
86
     */
87
    protected $listingOrder = 'desc';
88
89
    /**
90
     * @var integer
91
     */
92
    protected $headerId;
93
94
    /**
95
     * @var string
96
     */
97
    protected $hash;
98
99
    /**
100
     * @var DateTime
101
     */
102
    protected $accLockout;
103
104
    /**
105
     * @var integer
106
     */
107
    protected $passwordChangePeriod;
108
109
    /**
110
     * @var integer
111
     */
112
    protected $loginRetry = 0;
113
114
    /**
115
     * @var DateTime
116
     */
117
    protected $dateLastLogin = '0000-00-00 00:00:00';
118
119
    /**
120
     * @var DateTime
121
     */
122
    protected $datePasswordChanged;
123
124
    /**
125
     * @var DateTime
126
     */
127
    protected $dateLoginFailed;
128
129
    /**
130
     * @var integer
131
     */
132
    protected $mailNotify = 0;
133
134
    /**
135
     * @var integer
136
     */
137
    protected $bookstyle = 0;
138
139
    /**
140
     * @var string
141
     */
142
    protected $settingMetadata;
143
144
    //endregion
145
146
    //region Association properties
147
148
    protected $mails;
149
150
    //endregion
151
152
    //region Column methods
153
154
    public function getId()
155
    {
156
        return $this->id;
157
    }
158
159
    public function getLogin()
160
    {
161
        return $this->login;
162
    }
163
164
    public function setLogin($login)
165
    {
166
        $this->login = $login;
167
168
        return $this;
169
    }
170
171
    /**
172
     * Returns the password used to authenticate the user.
173
     *
174
     * @return string
175
     */
176
    public function getPassword()
177
    {
178
        return $this->password;
179
    }
180
181
    public function setPassword($password)
182
    {
183
        $this->password = $password;
184
185
        return $this;
186
    }
187
188
    public function getEmail()
189
    {
190
        return $this->email;
191
    }
192
193
    public function setEmail($email)
194
    {
195
        $this->email = $email;
196
197
        return $this;
198
    }
199
200
    public function getLastAction()
201
    {
202
        return $this->lastAction;
203
    }
204
205
    public function setLastAction($lastAction)
206
    {
207
        $this->lastAction = $lastAction;
208
209
        return $this;
210
    }
211
212
    public function getUserAction()
213
    {
214
        return $this->userAction;
215
    }
216
217
    public function setUserAction($userAction)
218
    {
219
        $this->userAction = $userAction;
220
221
        return $this;
222
    }
223
224
    public function getUserActionId()
225
    {
226
        return $this->userActionId;
227
    }
228
229
    public function setUserActionId($userActionId)
230
    {
231
        $this->userActionId = $userActionId;
232
233
        return $this;
234
    }
235
236
    public function getLocationVector()
237
    {
238
        return $this->locationVector;
239
    }
240
241
    public function setUserLocationVector($locationVector)
242
    {
243
        $this->locationVector = $locationVector;
244
245
        return $this;
246
    }
247
248
    public function getMailCount()
249
    {
250
        return $this->mailCount;
251
    }
252
253
    public function setMailCount($mailCount)
254
    {
255
        $this->mailCount = $mailCount;
256
257
        return $this;
258
    }
259
260
    public function getUserMailId()
261
    {
262
        return $this->userMailId;
263
    }
264
265
    public function setUserMailId($userMailId)
266
    {
267
        $this->userMailId = $userMailId;
268
269
        return $this;
270
    }
271
272
    public function getK()
273
    {
274
        return $this->k;
275
    }
276
277
    public function setK($k)
278
    {
279
        $this->k = $k;
280
281
        return $this;
282
    }
283
284
    public function getKWallet()
285
    {
286
        return $this->kWallet;
287
    }
288
289
    public function setKWallet($kWallet)
290
    {
291
        $this->kWallet = $kWallet;
292
293
        return $this;
294
    }
295
296
    public function getListingAmount()
297
    {
298
        return $this->listingAmount;
299
    }
300
301
    public function setListingAmount($listingAmount)
302
    {
303
        $this->listingAmount = $listingAmount;
304
305
        return $this;
306
    }
307
308
    public function getListingOrder()
309
    {
310
        return $this->listingOrder;
311
    }
312
313
    public function setListingOrder($listingOrder)
314
    {
315
        $this->listingOrder = $listingOrder;
316
317
        return $this;
318
    }
319
320
    public function getHeaderId()
321
    {
322
        return $this->headerId;
323
    }
324
325
    public function setHeaderId($headerId)
326
    {
327
        $this->headerId = $headerId;
328
329
        return $this;
330
    }
331
332
    public function getHash()
333
    {
334
        return $this->hash;
335
    }
336
337
    public function setHash($hash)
338
    {
339
        $this->hash = $hash;
340
341
        return $this;
342
    }
343
344
    public function getAccLockout()
345
    {
346
        return $this->accLockout;
347
    }
348
349
    public function setAccLockout($accLockout)
350
    {
351
        $this->accLockout = $accLockout;
352
353
        return $this;
354
    }
355
356
    public function getPasswordChangePeriod()
357
    {
358
        return $this->passwordChangePeriod;
359
    }
360
361
    public function setPasswordChangePeriod($passwordChangePeriod)
362
    {
363
        $this->passwordChangePeriod = $passwordChangePeriod;
364
365
        return $this;
366
    }
367
368
    public function getLoginRetry()
369
    {
370
        return $this->loginRetry;
371
    }
372
373
    public function setLoginRetry($loginRetry)
374
    {
375
        $this->loginRetry = $loginRetry;
376
377
        return $this;
378
    }
379
380
    public function getDateLastLogin()
381
    {
382
        return $this->dateLastLogin;
383
    }
384
385
    public function setDateLastLogin(DateTime $dateLastLogin)
386
    {
387
        $this->dateLastLogin = $dateLastLogin;
388
389
        return $this;
390
    }
391
392
    public function getDatePasswordChanged()
393
    {
394
        return $this->datePasswordChanged;
395
    }
396
397
    public function setDatePasswordChanged($datePasswordChanged)
398
    {
399
        $this->datePasswordChanged = $datePasswordChanged;
400
401
        return $this;
402
    }
403
404
    public function getDateLoginFailed()
405
    {
406
        return $this->dateLoginFailed;
407
    }
408
409
    public function setDateLoginFailed($dateLoginFailed)
410
    {
411
        $this->dateLoginFailed = $dateLoginFailed;
412
413
        return $this;
414
    }
415
416
    public function getMailNotify()
417
    {
418
        return $this->mailNotify;
419
    }
420
421
    public function setMailNotify($mailNotify)
422
    {
423
        $this->mailNotify = $mailNotify;
424
425
        return $this;
426
    }
427
428
    //endregion
429
430
    //region Association methods
431
432
    public function getMails()
433
    {
434
        return $this->mails;
435
    }
436
437
    public function setMails($mails)
438
    {
439
        $this->mails = $mails;
440
441
        return $this;
442
    }
443
444
    //endregion
445
446
    //region UserInterface
447
448
    /**
449
     * Returns the username used to authenticate the user.
450
     *
451
     * @return string The username
452
     */
453
    public function getUsername()
454
    {
455
        return $this->login;
456
    }
457
458
    /**
459
     * Returns the roles granted to the user.
460
     *
461
     * Alternatively, the roles might be stored on a ``roles`` property,
462
     * and populated in any number of different ways when the user object
463
     * is created.
464
     *
465
     * @return (Role|string)[] The user roles
466
     */
467
    public function getRoles()
468
    {
469
        return [
470
            'ROLE_USER',
471
        ];
472
    }
473
474
    /**
475
     * Returns the salt that was originally used to encode the password.
476
     *
477
     * This can return null if the password was not encoded using a salt.
478
     *
479
     * @return string|null The salt
480
     */
481
    public function getSalt()
482
    {
483
        return null;
484
    }
485
486
    /**
487
     * Removes sensitive data from the user.
488
     *
489
     * This is important if, at any given point, sensitive information like
490
     * the plain-text password is stored on this object.
491
     */
492
    public function eraseCredentials()
493
    {
494
        return;
495
    }
496
497
    //endregion
498
499
    //region AdvancedUserInterface
500
501
    /**
502
     * Checks whether the user's account has expired.
503
     *
504
     * Internally, if this method returns false, the authentication system
505
     * will throw an AccountExpiredException and prevent login.
506
     *
507
     * @return bool true if the user's account is non expired, false otherwise
508
     *
509
     * @see AccountExpiredException
510
     */
511
    public function isAccountNonExpired()
512
    {
513
        return true;
514
    }
515
516
    /**
517
     * Checks whether the user is locked.
518
     *
519
     * Internally, if this method returns false, the authentication system
520
     * will throw a LockedException and prevent login.
521
     *
522
     * @return bool true if the user is not locked, false otherwise
523
     *
524
     * @see LockedException
525
     */
526
    public function isAccountNonLocked()
527
    {
528
        $now = new DateTime();
529
530
        return (empty($this->accLockout) || $this->accLockout <= $now);
531
    }
532
533
    /**
534
     * Checks whether the user's credentials (password) has expired.
535
     *
536
     * Internally, if this method returns false, the authentication system
537
     * will throw a CredentialsExpiredException and prevent login.
538
     *
539
     * @return bool true if the user's credentials are non expired, false otherwise
540
     *
541
     * @see CredentialsExpiredException
542
     */
543
    public function isCredentialsNonExpired()
544
    {
545
        return true;
546
    }
547
548
    /**
549
     * Checks whether the user is enabled.
550
     *
551
     * Internally, if this method returns false, the authentication system
552
     * will throw a DisabledException and prevent login.
553
     *
554
     * @return bool true if the user is enabled, false otherwise
555
     *
556
     * @see DisabledException
557
     */
558
    public function isEnabled()
559
    {
560
        //TODO this should return false for users with pending registrations
561
        return true;
562
    }
563
564
    //endregion
565
566
    //region EncoderAwareInterface
567
568
    /**
569
     * Gets the name of the encoder used to encode the password.
570
     *
571
     * If the method returns null, the standard way to retrieve the encoder
572
     * will be used instead.
573
     *
574
     * @return string
575
     */
576
    public function getEncoderName()
577
    {
578
        if (strlen($this->password) === 32) {
579
            return self::ENCODER_MD5;
580
        } elseif (strlen($this->password) === 80 && $this->password[0] !== '$') {
581
            return self::ENCODER_SHA;
582
        } else {
583
            return self::ENCODER_BCRYPT;
584
        }
585
    }
586
587
    //endregion
588
589
    //region Serializable
590
591
    /**
592
     * @see \Serializable::serialize()
593
     */
594
    public function serialize()
595
    {
596
        return serialize([
597
            $this->id,
598
            $this->login,
599
            $this->password,
600
            $this->accLockout,
601
        ]);
602
    }
603
604
    /**
605
     * @param string $serialized
606
     * @see \Serializable::unserialize()
607
     */
608
    public function unserialize($serialized)
609
    {
610
        list(
611
            $this->id,
612
            $this->login,
613
            $this->password,
614
            $this->accLockout
615
        ) = unserialize($serialized);
616
    }
617
618
    //endregion
619
}
620