1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
/* |
|
|
|
|
4
|
|
|
* This file is part of the DoyoUserBundle project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Doyo\UserBundle\Model; |
15
|
|
|
|
16
|
|
|
class User implements UserInterface |
|
|
|
|
17
|
|
|
{ |
|
|
|
|
18
|
|
|
/** |
|
|
|
|
19
|
|
|
* @var string|int|null |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
protected $id; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
|
|
|
|
24
|
|
|
* @var string|null |
25
|
|
|
*/ |
26
|
|
|
protected $username; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
|
|
|
|
29
|
|
|
* @var string|null |
30
|
|
|
*/ |
31
|
|
|
protected $usernameCanonical; |
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
|
|
|
|
34
|
|
|
* @var string|null |
35
|
|
|
*/ |
36
|
|
|
protected $email; |
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
|
|
|
|
39
|
|
|
* @var string|null |
40
|
|
|
*/ |
41
|
|
|
protected $emailCanonical; |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
|
|
|
|
44
|
|
|
* @var bool |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
protected $enabled; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
|
|
|
|
49
|
|
|
* @var array|null |
50
|
|
|
*/ |
51
|
|
|
protected $roles; |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
|
|
|
|
54
|
|
|
* @var string|null |
55
|
|
|
*/ |
56
|
|
|
protected $plainPassword; |
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
|
|
|
|
59
|
|
|
* @var string|null |
60
|
|
|
*/ |
61
|
|
|
protected $password; |
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
|
|
|
|
64
|
|
|
* @var string|null |
65
|
|
|
*/ |
66
|
|
|
protected $salt; |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
|
|
|
|
69
|
|
|
* @var \DateTimeImmutable|null |
70
|
|
|
*/ |
71
|
|
|
protected $lastLogin; |
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
|
|
|
|
74
|
|
|
* @var string|null |
75
|
|
|
*/ |
76
|
|
|
protected $confirmationToken; |
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
|
|
|
|
79
|
|
|
* @var \DateTimeImmutable|null |
80
|
|
|
*/ |
81
|
|
|
protected $passwordRequestedAt; |
|
|
|
|
82
|
|
|
|
83
|
7 |
|
public function __construct() |
|
|
|
|
84
|
|
|
{ |
|
|
|
|
85
|
7 |
|
$this->roles = ['ROLE_USER']; |
|
|
|
|
86
|
7 |
|
$this->enabled = false; |
|
|
|
|
87
|
|
|
} |
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
|
|
|
|
90
|
|
|
* @return int|string|null |
|
|
|
|
91
|
|
|
*/ |
92
|
3 |
|
public function getId() |
93
|
|
|
{ |
|
|
|
|
94
|
3 |
|
return $this->id; |
95
|
|
|
} |
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
|
|
|
|
98
|
|
|
* @param string $role |
|
|
|
|
99
|
|
|
* |
100
|
|
|
* @return static |
101
|
|
|
*/ |
102
|
2 |
|
public function addRole($role) |
|
|
|
|
103
|
|
|
{ |
|
|
|
|
104
|
2 |
|
$role = strtoupper($role); |
105
|
|
|
|
106
|
2 |
|
if (!$this->hasRole($role)) { |
|
|
|
|
107
|
2 |
|
$this->roles[] = $role; |
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
return $this; |
111
|
|
|
} |
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
|
|
|
|
114
|
|
|
* @param string $role |
|
|
|
|
115
|
|
|
*/ |
|
|
|
|
116
|
2 |
|
public function hasRole($role): bool |
|
|
|
|
117
|
|
|
{ |
|
|
|
|
118
|
2 |
|
$role = strtoupper($role); |
119
|
|
|
|
120
|
2 |
|
return \in_array($role, $this->roles, true); |
|
|
|
|
121
|
|
|
} |
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
|
|
|
|
124
|
|
|
* @param string $role |
|
|
|
|
125
|
|
|
* |
126
|
|
|
* @return static |
127
|
|
|
*/ |
128
|
1 |
|
public function removeRole($role) |
|
|
|
|
129
|
|
|
{ |
|
|
|
|
130
|
1 |
|
if (false !== $key = array_search(strtoupper($role), $this->roles, true)) { |
|
|
|
|
131
|
1 |
|
unset($this->roles[$key]); |
132
|
1 |
|
$this->roles = array_values($this->roles); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
return $this; |
136
|
|
|
} |
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
|
|
|
|
139
|
|
|
* @return static |
140
|
|
|
*/ |
141
|
1 |
|
public function setRoles(?array $roles) |
142
|
|
|
{ |
|
|
|
|
143
|
1 |
|
$this->roles = []; |
|
|
|
|
144
|
|
|
|
145
|
1 |
|
foreach ($roles as $role) { |
146
|
1 |
|
$this->addRole($role); |
147
|
|
|
} |
148
|
|
|
|
149
|
1 |
|
return $this; |
150
|
|
|
} |
|
|
|
|
151
|
|
|
|
152
|
5 |
|
public function getSalt(): ?string |
|
|
|
|
153
|
|
|
{ |
|
|
|
|
154
|
5 |
|
return $this->salt; |
155
|
|
|
} |
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
|
|
|
|
158
|
|
|
* @return static |
159
|
|
|
*/ |
160
|
5 |
|
public function setSalt(?string $salt) |
161
|
|
|
{ |
|
|
|
|
162
|
5 |
|
$this->salt = $salt; |
163
|
|
|
|
164
|
5 |
|
return $this; |
165
|
|
|
} |
|
|
|
|
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
*/ |
|
|
|
|
170
|
5 |
|
public function eraseCredentials() |
171
|
|
|
{ |
|
|
|
|
172
|
5 |
|
$this->plainPassword = null; |
|
|
|
|
173
|
|
|
} |
|
|
|
|
174
|
|
|
|
175
|
2 |
|
public function isEnabled(): bool |
|
|
|
|
176
|
|
|
{ |
|
|
|
|
177
|
2 |
|
return $this->enabled; |
178
|
|
|
} |
|
|
|
|
179
|
|
|
|
180
|
|
|
/** |
|
|
|
|
181
|
|
|
* @return static |
182
|
|
|
*/ |
183
|
5 |
|
public function setEnabled(bool $enabled) |
184
|
|
|
{ |
|
|
|
|
185
|
5 |
|
$this->enabled = $enabled; |
186
|
|
|
|
187
|
5 |
|
return $this; |
188
|
|
|
} |
|
|
|
|
189
|
|
|
|
190
|
5 |
|
public function getUsername(): ?string |
|
|
|
|
191
|
|
|
{ |
|
|
|
|
192
|
5 |
|
return $this->username; |
193
|
|
|
} |
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
|
|
|
|
196
|
|
|
* @return static |
197
|
|
|
*/ |
198
|
5 |
|
public function setUsername(?string $username) |
199
|
|
|
{ |
|
|
|
|
200
|
5 |
|
$this->username = $username; |
201
|
|
|
|
202
|
5 |
|
return $this; |
203
|
|
|
} |
|
|
|
|
204
|
|
|
|
205
|
1 |
|
public function getUsernameCanonical(): ?string |
|
|
|
|
206
|
|
|
{ |
|
|
|
|
207
|
1 |
|
return $this->usernameCanonical; |
208
|
|
|
} |
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
|
|
|
|
211
|
|
|
* @return static |
212
|
|
|
*/ |
213
|
5 |
|
public function setUsernameCanonical(?string $usernameCanonical) |
214
|
|
|
{ |
|
|
|
|
215
|
5 |
|
$this->usernameCanonical = $usernameCanonical; |
216
|
|
|
|
217
|
5 |
|
return $this; |
218
|
|
|
} |
|
|
|
|
219
|
|
|
|
220
|
5 |
|
public function getEmail(): ?string |
|
|
|
|
221
|
|
|
{ |
|
|
|
|
222
|
5 |
|
return $this->email; |
223
|
|
|
} |
|
|
|
|
224
|
|
|
|
225
|
|
|
/** |
|
|
|
|
226
|
|
|
* @return static |
227
|
|
|
*/ |
228
|
5 |
|
public function setEmail(?string $email) |
229
|
|
|
{ |
|
|
|
|
230
|
5 |
|
$this->email = $email; |
231
|
|
|
|
232
|
5 |
|
return $this; |
233
|
|
|
} |
|
|
|
|
234
|
|
|
|
235
|
1 |
|
public function getEmailCanonical(): ?string |
|
|
|
|
236
|
|
|
{ |
|
|
|
|
237
|
1 |
|
return $this->emailCanonical; |
238
|
|
|
} |
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
|
|
|
|
241
|
|
|
* @return static |
242
|
|
|
*/ |
243
|
5 |
|
public function setEmailCanonical(?string $emailCanonical) |
244
|
|
|
{ |
|
|
|
|
245
|
5 |
|
$this->emailCanonical = $emailCanonical; |
246
|
|
|
|
247
|
5 |
|
return $this; |
248
|
|
|
} |
|
|
|
|
249
|
|
|
|
250
|
4 |
|
public function getRoles(): ?array |
|
|
|
|
251
|
|
|
{ |
|
|
|
|
252
|
4 |
|
return $this->roles; |
253
|
|
|
} |
|
|
|
|
254
|
|
|
|
255
|
6 |
|
public function getPlainPassword(): ?string |
|
|
|
|
256
|
|
|
{ |
|
|
|
|
257
|
6 |
|
return $this->plainPassword; |
258
|
|
|
} |
|
|
|
|
259
|
|
|
|
260
|
|
|
/** |
|
|
|
|
261
|
|
|
* @return static |
262
|
|
|
*/ |
263
|
6 |
|
public function setPlainPassword(?string $plainPassword) |
264
|
|
|
{ |
|
|
|
|
265
|
6 |
|
$this->plainPassword = $plainPassword; |
266
|
|
|
|
267
|
6 |
|
return $this; |
268
|
|
|
} |
|
|
|
|
269
|
|
|
|
270
|
2 |
|
public function getPassword(): ?string |
|
|
|
|
271
|
|
|
{ |
|
|
|
|
272
|
2 |
|
return $this->password; |
273
|
|
|
} |
|
|
|
|
274
|
|
|
|
275
|
|
|
/** |
|
|
|
|
276
|
|
|
* @return static |
277
|
|
|
*/ |
278
|
5 |
|
public function setPassword(?string $password) |
279
|
|
|
{ |
|
|
|
|
280
|
5 |
|
$this->password = $password; |
281
|
|
|
|
282
|
5 |
|
return $this; |
283
|
|
|
} |
|
|
|
|
284
|
|
|
|
285
|
2 |
|
public function getLastLogin(): ?\DateTimeImmutable |
|
|
|
|
286
|
|
|
{ |
|
|
|
|
287
|
2 |
|
return $this->lastLogin; |
288
|
|
|
} |
|
|
|
|
289
|
|
|
|
290
|
|
|
/** |
|
|
|
|
291
|
|
|
* @return static |
292
|
|
|
*/ |
293
|
1 |
|
public function setLastLogin(?\DateTimeImmutable $lastLogin) |
294
|
|
|
{ |
|
|
|
|
295
|
1 |
|
$this->lastLogin = $lastLogin; |
296
|
|
|
|
297
|
1 |
|
return $this; |
298
|
|
|
} |
|
|
|
|
299
|
|
|
|
300
|
1 |
|
public function getConfirmationToken(): ?string |
|
|
|
|
301
|
|
|
{ |
|
|
|
|
302
|
1 |
|
return $this->confirmationToken; |
303
|
|
|
} |
|
|
|
|
304
|
|
|
|
305
|
|
|
/** |
|
|
|
|
306
|
|
|
* @return static |
307
|
|
|
*/ |
308
|
1 |
|
public function setConfirmationToken(?string $confirmationToken) |
309
|
|
|
{ |
|
|
|
|
310
|
1 |
|
$this->confirmationToken = $confirmationToken; |
311
|
|
|
|
312
|
1 |
|
return $this; |
313
|
|
|
} |
|
|
|
|
314
|
|
|
|
315
|
1 |
|
public function getPasswordRequestedAt(): ?\DateTimeImmutable |
|
|
|
|
316
|
|
|
{ |
|
|
|
|
317
|
1 |
|
return $this->passwordRequestedAt; |
318
|
|
|
} |
|
|
|
|
319
|
|
|
|
320
|
|
|
/** |
|
|
|
|
321
|
|
|
* @return static |
322
|
|
|
*/ |
323
|
1 |
|
public function setPasswordRequestedAt(?\DateTimeImmutable $passwordRequestedAt) |
324
|
|
|
{ |
|
|
|
|
325
|
1 |
|
$this->passwordRequestedAt = $passwordRequestedAt; |
326
|
|
|
|
327
|
1 |
|
return $this; |
328
|
|
|
} |
|
|
|
|
329
|
|
|
} |
|
|
|
|
330
|
|
|
|