1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Entity User. |
5
|
|
|
* |
6
|
|
|
* PHP Version 7 |
7
|
|
|
* |
8
|
|
|
* @author Quétier Laurent <[email protected]> |
9
|
|
|
* @copyright 2018 Dev-Int GLSR |
10
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
11
|
|
|
* |
12
|
|
|
* @version GIT: $Id$ |
13
|
|
|
* |
14
|
|
|
* @link https://github.com/Dev-Int/glsr |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace App\Entity; |
18
|
|
|
|
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
20
|
|
|
use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Table(name="app_users") |
24
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository") |
25
|
|
|
*/ |
26
|
|
|
class User implements AdvancedUserInterface, \Serializable |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @ORM\Column(type="integer") |
30
|
|
|
* @ORM\Id |
31
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
32
|
|
|
*/ |
33
|
|
|
private $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="string", length=25, unique=true) |
37
|
|
|
*/ |
38
|
|
|
private $username; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\Column(type="string", length=64) |
42
|
|
|
*/ |
43
|
|
|
private $password; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @ORM\Column(type="string", length=254, unique=true) |
47
|
|
|
*/ |
48
|
|
|
private $email; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\Column(type="array") |
52
|
|
|
*/ |
53
|
|
|
private $roles; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
57
|
|
|
*/ |
58
|
|
|
private $isActive; |
59
|
|
|
|
60
|
|
|
public function __construct() |
61
|
|
|
{ |
62
|
|
|
$this->isActive = true; |
63
|
|
|
// may not be needed, see section on salt below |
64
|
|
|
// $this->salt = md5(uniqid('', true)); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getUsername() |
68
|
|
|
{ |
69
|
|
|
return $this->username; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getEmail() |
73
|
|
|
{ |
74
|
|
|
return $this->email; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getSalt() |
78
|
|
|
{ |
79
|
|
|
// you *may* need a real salt depending on your encoder |
80
|
|
|
// see section on salt below |
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getPassword() |
85
|
|
|
{ |
86
|
|
|
return $this->password; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getRoles() |
90
|
|
|
{ |
91
|
|
|
return $this->roles; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function eraseCredentials() |
95
|
|
|
{ |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function isAccountNonExpired() |
99
|
|
|
{ |
100
|
|
|
return true; |
101
|
|
|
} |
102
|
|
|
public function isAccountNonLocked() |
103
|
|
|
{ |
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
public function isCredentialsNonExpired() |
107
|
|
|
{ |
108
|
|
|
return true; |
109
|
|
|
} |
110
|
|
|
public function isEnabled() |
111
|
|
|
{ |
112
|
|
|
return $this->isActive; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** @see \Serializable::serialize() */ |
116
|
|
|
public function serialize() |
117
|
|
|
{ |
118
|
|
|
return serialize(array( |
119
|
|
|
$this->id, |
120
|
|
|
$this->username, |
121
|
|
|
$this->password, |
122
|
|
|
$this->isActive, |
123
|
|
|
// see section on salt below |
124
|
|
|
// $this->salt, |
125
|
|
|
)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** @see \Serializable::unserialize() */ |
129
|
|
|
public function unserialize($serialized) |
130
|
|
|
{ |
131
|
|
|
list ( |
132
|
|
|
$this->id, |
133
|
|
|
$this->username, |
134
|
|
|
$this->password, |
135
|
|
|
$this->isActive, |
136
|
|
|
// see section on salt below |
137
|
|
|
// $this->salt |
138
|
|
|
) = unserialize($serialized, ['allowed_classes' => false]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getId(): ?int |
142
|
|
|
{ |
143
|
|
|
return $this->id; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setUsername(string $username): self |
147
|
|
|
{ |
148
|
|
|
$this->username = $username; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setPassword(string $password): self |
154
|
|
|
{ |
155
|
|
|
$this->password = $password; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function setEmail(string $email): self |
161
|
|
|
{ |
162
|
|
|
$this->email = $email; |
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getIsActive(): ?bool |
|
|
|
|
168
|
|
|
{ |
169
|
|
|
return $this->isActive; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function setIsActive(bool $isActive): self |
173
|
|
|
{ |
174
|
|
|
$this->isActive = $isActive; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function setRoles(array $roles): self |
180
|
|
|
{ |
181
|
|
|
$this->roles = $roles; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
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.