|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* /src/Entity/User.php |
|
5
|
|
|
* |
|
6
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Entity; |
|
10
|
|
|
|
|
11
|
|
|
use App\Doctrine\DBAL\Types\Types as AppTypes; |
|
12
|
|
|
use App\Entity\Interfaces\EntityInterface; |
|
13
|
|
|
use App\Entity\Interfaces\UserGroupAwareInterface; |
|
14
|
|
|
use App\Entity\Interfaces\UserInterface; |
|
15
|
|
|
use App\Entity\Traits\Blameable; |
|
16
|
|
|
use App\Entity\Traits\Timestampable; |
|
17
|
|
|
use App\Entity\Traits\UserRelations; |
|
18
|
|
|
use App\Entity\Traits\Uuid; |
|
19
|
|
|
use App\Enum\Language; |
|
20
|
|
|
use App\Enum\Locale; |
|
21
|
|
|
use App\Service\Localization; |
|
|
|
|
|
|
22
|
|
|
use App\Validator\Constraints as AppAssert; |
|
23
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
24
|
|
|
use Doctrine\DBAL\Types\Types; |
|
25
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
26
|
|
|
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType; |
|
27
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
28
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as AssertCollection; |
|
29
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
30
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class User |
|
34
|
|
|
* |
|
35
|
|
|
* @package App\Entity |
|
36
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
#[ORM\Entity] |
|
39
|
|
|
#[ORM\Table( |
|
40
|
|
|
name: 'user', |
|
41
|
|
|
)] |
|
42
|
|
|
#[ORM\UniqueConstraint( |
|
43
|
|
|
name: 'uq_username', |
|
44
|
|
|
columns: [ |
|
45
|
|
|
'username', |
|
46
|
|
|
], |
|
47
|
|
|
)] |
|
48
|
|
|
#[ORM\UniqueConstraint( |
|
49
|
|
|
name: 'uq_email', |
|
50
|
|
|
columns: [ |
|
51
|
|
|
'email', |
|
52
|
|
|
], |
|
53
|
|
|
)] |
|
54
|
|
|
#[ORM\ChangeTrackingPolicy('DEFERRED_EXPLICIT')] |
|
55
|
|
|
#[AssertCollection\UniqueEntity('email')] |
|
56
|
|
|
#[AssertCollection\UniqueEntity('username')] |
|
57
|
|
|
class User implements EntityInterface, UserInterface, UserGroupAwareInterface |
|
58
|
|
|
{ |
|
59
|
|
|
use Blameable; |
|
60
|
|
|
use Timestampable; |
|
61
|
|
|
use UserRelations; |
|
62
|
|
|
use Uuid; |
|
63
|
|
|
|
|
64
|
|
|
final public const SET_USER_PROFILE = 'set.UserProfile'; |
|
65
|
|
|
final public const SET_USER_BASIC = 'set.UserBasic'; |
|
66
|
|
|
|
|
67
|
|
|
#[ORM\Id] |
|
68
|
|
|
#[ORM\Column( |
|
69
|
|
|
name: 'id', |
|
70
|
|
|
type: UuidBinaryOrderedTimeType::NAME, |
|
71
|
|
|
unique: true, |
|
72
|
|
|
nullable: false, |
|
73
|
|
|
)] |
|
74
|
|
|
#[Groups([ |
|
75
|
|
|
'User', |
|
76
|
|
|
'User.id', |
|
77
|
|
|
|
|
78
|
|
|
'LogLogin.user', |
|
79
|
|
|
'LogLoginFailure.user', |
|
80
|
|
|
'LogRequest.user', |
|
81
|
|
|
|
|
82
|
|
|
'UserGroup.users', |
|
83
|
|
|
|
|
84
|
|
|
self::SET_USER_PROFILE, |
|
85
|
|
|
self::SET_USER_BASIC, |
|
86
|
|
|
])] |
|
87
|
|
|
private UuidInterface $id; |
|
88
|
|
|
|
|
89
|
|
|
#[ORM\Column( |
|
90
|
|
|
name: 'username', |
|
91
|
|
|
type: Types::STRING, |
|
92
|
|
|
length: 255, |
|
93
|
|
|
nullable: false, |
|
94
|
|
|
)] |
|
95
|
|
|
#[Groups([ |
|
96
|
|
|
'User', |
|
97
|
|
|
'User.username', |
|
98
|
|
|
|
|
99
|
|
|
self::SET_USER_PROFILE, |
|
100
|
|
|
self::SET_USER_BASIC, |
|
101
|
|
|
])] |
|
102
|
|
|
#[Assert\NotBlank] |
|
103
|
|
|
#[Assert\NotNull] |
|
104
|
|
|
#[Assert\Length( |
|
105
|
|
|
min: 2, |
|
106
|
|
|
max: 255, |
|
107
|
|
|
)] |
|
108
|
|
|
private string $username = ''; |
|
109
|
|
|
|
|
110
|
|
|
#[ORM\Column( |
|
111
|
|
|
name: 'first_name', |
|
112
|
|
|
type: Types::STRING, |
|
113
|
|
|
length: 255, |
|
114
|
|
|
nullable: false, |
|
115
|
|
|
)] |
|
116
|
|
|
#[Groups([ |
|
117
|
|
|
'User', |
|
118
|
|
|
'User.firstName', |
|
119
|
|
|
|
|
120
|
|
|
self::SET_USER_PROFILE, |
|
121
|
|
|
self::SET_USER_BASIC, |
|
122
|
|
|
])] |
|
123
|
|
|
#[Assert\NotBlank] |
|
124
|
|
|
#[Assert\NotNull] |
|
125
|
|
|
#[Assert\Length( |
|
126
|
|
|
min: 2, |
|
127
|
|
|
max: 255, |
|
128
|
|
|
)] |
|
129
|
|
|
private string $firstName = ''; |
|
130
|
|
|
|
|
131
|
|
|
#[ORM\Column( |
|
132
|
|
|
name: 'last_name', |
|
133
|
|
|
type: Types::STRING, |
|
134
|
|
|
length: 255, |
|
135
|
|
|
nullable: false, |
|
136
|
|
|
)] |
|
137
|
|
|
#[Groups([ |
|
138
|
|
|
'User', |
|
139
|
|
|
'User.lastName', |
|
140
|
|
|
|
|
141
|
|
|
self::SET_USER_PROFILE, |
|
142
|
|
|
self::SET_USER_BASIC, |
|
143
|
|
|
])] |
|
144
|
|
|
#[Assert\NotBlank] |
|
145
|
|
|
#[Assert\NotNull] |
|
146
|
|
|
#[Assert\Length( |
|
147
|
|
|
min: 2, |
|
148
|
|
|
max: 255, |
|
149
|
|
|
)] |
|
150
|
|
|
private string $lastName = ''; |
|
151
|
|
|
|
|
152
|
|
|
#[ORM\Column( |
|
153
|
|
|
name: 'email', |
|
154
|
|
|
type: Types::STRING, |
|
155
|
|
|
length: 255, |
|
156
|
|
|
nullable: false, |
|
157
|
|
|
)] |
|
158
|
|
|
#[Groups([ |
|
159
|
|
|
'User', |
|
160
|
|
|
'User.email', |
|
161
|
|
|
|
|
162
|
|
|
self::SET_USER_PROFILE, |
|
163
|
|
|
self::SET_USER_BASIC, |
|
164
|
|
|
])] |
|
165
|
|
|
#[Assert\NotBlank] |
|
166
|
|
|
#[Assert\NotNull] |
|
167
|
|
|
#[Assert\Email] |
|
168
|
|
|
private string $email = ''; |
|
169
|
|
|
|
|
170
|
|
|
#[ORM\Column( |
|
171
|
|
|
name: 'language', |
|
172
|
|
|
type: AppTypes::ENUM_LANGUAGE, |
|
173
|
|
|
nullable: false, |
|
174
|
|
|
options: [ |
|
175
|
|
|
'comment' => 'User language for translations', |
|
176
|
|
|
], |
|
177
|
|
|
)] |
|
178
|
|
|
#[Groups([ |
|
179
|
|
|
'User', |
|
180
|
|
|
'User.language', |
|
181
|
|
|
|
|
182
|
|
|
self::SET_USER_PROFILE, |
|
183
|
|
|
self::SET_USER_BASIC, |
|
184
|
|
|
])] |
|
185
|
|
|
#[Assert\NotBlank] |
|
186
|
|
|
#[Assert\NotNull] |
|
187
|
|
|
private Language $language; |
|
188
|
|
|
|
|
189
|
|
|
#[ORM\Column( |
|
190
|
|
|
name: 'locale', |
|
191
|
|
|
type: AppTypes::ENUM_LOCALE, |
|
192
|
|
|
nullable: false, |
|
193
|
|
|
options: [ |
|
194
|
|
|
'comment' => 'User locale for number, time, date, etc. formatting.', |
|
195
|
|
|
], |
|
196
|
|
|
)] |
|
197
|
|
|
#[Groups([ |
|
198
|
|
|
'User', |
|
199
|
|
|
'User.locale', |
|
200
|
|
|
|
|
201
|
|
|
self::SET_USER_PROFILE, |
|
202
|
|
|
self::SET_USER_BASIC, |
|
203
|
|
|
])] |
|
204
|
|
|
#[Assert\NotBlank] |
|
205
|
|
|
#[Assert\NotNull] |
|
206
|
|
|
private Locale $locale; |
|
207
|
|
|
|
|
208
|
|
|
#[ORM\Column( |
|
209
|
|
|
name: 'timezone', |
|
210
|
|
|
type: Types::STRING, |
|
211
|
|
|
length: 255, |
|
212
|
|
|
nullable: false, |
|
213
|
|
|
options: [ |
|
214
|
|
|
'comment' => 'User timezone which should be used to display time, date, etc.', |
|
215
|
|
|
'default' => Localization::DEFAULT_TIMEZONE, |
|
216
|
|
|
], |
|
217
|
|
|
)] |
|
218
|
|
|
#[Groups([ |
|
219
|
|
|
'User', |
|
220
|
|
|
'User.timezone', |
|
221
|
|
|
|
|
222
|
|
|
self::SET_USER_PROFILE, |
|
223
|
|
|
self::SET_USER_BASIC, |
|
224
|
|
|
])] |
|
225
|
|
|
#[Assert\NotBlank] |
|
226
|
|
|
#[Assert\NotNull] |
|
227
|
|
|
#[AppAssert\Timezone] |
|
228
|
|
|
private string $timezone = Localization::DEFAULT_TIMEZONE; |
|
229
|
|
|
|
|
230
|
|
|
#[ORM\Column( |
|
231
|
|
|
name: 'password', |
|
232
|
|
|
type: Types::STRING, |
|
233
|
|
|
length: 255, |
|
234
|
|
|
nullable: false, |
|
235
|
|
|
options: [ |
|
236
|
|
|
'comment' => 'Hashed password', |
|
237
|
|
|
], |
|
238
|
|
|
)] |
|
239
|
|
|
private string $password = ''; |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Plain password. Used for model validation. Must not be persisted. |
|
243
|
|
|
* |
|
244
|
|
|
* @see UserEntityEventListener |
|
245
|
|
|
*/ |
|
246
|
|
|
private string $plainPassword = ''; |
|
247
|
|
|
|
|
248
|
252 |
|
public function __construct() |
|
249
|
|
|
{ |
|
250
|
252 |
|
$this->id = $this->createUuid(); |
|
251
|
252 |
|
$this->language = Language::getDefault(); |
|
252
|
252 |
|
$this->locale = Locale::getDefault(); |
|
253
|
|
|
|
|
254
|
252 |
|
$this->userGroups = new ArrayCollection(); |
|
255
|
252 |
|
$this->logsRequest = new ArrayCollection(); |
|
256
|
252 |
|
$this->logsLogin = new ArrayCollection(); |
|
257
|
252 |
|
$this->logsLoginFailure = new ArrayCollection(); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
324 |
|
public function getId(): string |
|
261
|
|
|
{ |
|
262
|
324 |
|
return $this->id->toString(); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
126 |
|
public function getUsername(): string |
|
266
|
|
|
{ |
|
267
|
126 |
|
return $this->username; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
30 |
|
public function setUsername(string $username): self |
|
271
|
|
|
{ |
|
272
|
30 |
|
$this->username = $username; |
|
273
|
|
|
|
|
274
|
30 |
|
return $this; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
64 |
|
public function getFirstName(): string |
|
278
|
|
|
{ |
|
279
|
64 |
|
return $this->firstName; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
26 |
|
public function setFirstName(string $firstName): self |
|
283
|
|
|
{ |
|
284
|
26 |
|
$this->firstName = $firstName; |
|
285
|
|
|
|
|
286
|
26 |
|
return $this; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
64 |
|
public function getLastName(): string |
|
290
|
|
|
{ |
|
291
|
64 |
|
return $this->lastName; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
26 |
|
public function setLastName(string $lastName): self |
|
295
|
|
|
{ |
|
296
|
26 |
|
$this->lastName = $lastName; |
|
297
|
|
|
|
|
298
|
26 |
|
return $this; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
66 |
|
public function getEmail(): string |
|
302
|
|
|
{ |
|
303
|
66 |
|
return $this->email; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
28 |
|
public function setEmail(string $email): self |
|
307
|
|
|
{ |
|
308
|
28 |
|
$this->email = $email; |
|
309
|
|
|
|
|
310
|
28 |
|
return $this; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
312 |
|
public function getLanguage(): Language |
|
314
|
|
|
{ |
|
315
|
312 |
|
return $this->language; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
17 |
|
public function setLanguage(Language $language): self |
|
319
|
|
|
{ |
|
320
|
17 |
|
$this->language = $language; |
|
321
|
|
|
|
|
322
|
17 |
|
return $this; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
312 |
|
public function getLocale(): Locale |
|
326
|
|
|
{ |
|
327
|
312 |
|
return $this->locale; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
18 |
|
public function setLocale(Locale $locale): self |
|
331
|
|
|
{ |
|
332
|
18 |
|
$this->locale = $locale; |
|
333
|
|
|
|
|
334
|
18 |
|
return $this; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
312 |
|
public function getTimezone(): string |
|
338
|
|
|
{ |
|
339
|
312 |
|
return $this->timezone; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
5 |
|
public function setTimezone(string $timezone): self |
|
343
|
|
|
{ |
|
344
|
5 |
|
$this->timezone = $timezone; |
|
345
|
|
|
|
|
346
|
5 |
|
return $this; |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
310 |
|
public function getPassword(): string |
|
350
|
|
|
{ |
|
351
|
310 |
|
return $this->password; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
22 |
|
public function setPassword(callable $encoder, string $plainPassword): self |
|
355
|
|
|
{ |
|
356
|
22 |
|
$this->password = (string)$encoder($plainPassword); |
|
357
|
|
|
|
|
358
|
22 |
|
return $this; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
26 |
|
public function getPlainPassword(): string |
|
362
|
|
|
{ |
|
363
|
26 |
|
return $this->plainPassword; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
20 |
|
public function setPlainPassword(string $plainPassword): self |
|
367
|
|
|
{ |
|
368
|
20 |
|
if ($plainPassword !== '') { |
|
369
|
19 |
|
$this->plainPassword = $plainPassword; |
|
370
|
|
|
|
|
371
|
|
|
// Change some mapped values so preUpdate will get called - just blank it out |
|
372
|
19 |
|
$this->password = ''; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
20 |
|
return $this; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* Removes sensitive data from the user. |
|
380
|
|
|
* |
|
381
|
|
|
* This is important if, at any given point, sensitive information like |
|
382
|
|
|
* the plain-text password is stored on this object. |
|
383
|
|
|
*/ |
|
384
|
16 |
|
public function eraseCredentials(): void |
|
385
|
|
|
{ |
|
386
|
16 |
|
$this->plainPassword = ''; |
|
387
|
|
|
} |
|
388
|
|
|
} |
|
389
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths