1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2020-2024 Iain Cambridge |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by |
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Parthenon\User\Entity; |
23
|
|
|
|
24
|
|
|
use Doctrine\Common\Collections\Collection; |
25
|
|
|
use Parthenon\Athena\Entity\DeletableInterface; |
26
|
|
|
use Symfony\Component\Security\Core\User\EquatableInterface; |
27
|
|
|
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; |
28
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
29
|
|
|
|
30
|
|
|
class User implements UserInterface, EquatableInterface, DeletableInterface |
31
|
|
|
{ |
32
|
|
|
public const DEFAULT_ROLE = 'ROLE_USER'; |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
#[Assert\NotBlank(message: 'parthenon.user.validation.email.not_blank')] |
36
|
|
|
#[Assert\Email(message: 'parthenon.user.validation.email.email')] |
37
|
|
|
protected string $email; |
38
|
|
|
|
39
|
|
|
#[Assert\NotBlank(message: 'parthenon.user.validation.password.not_blank')] |
40
|
|
|
#[Assert\Length(min: 8, minMessage: 'parthenon.user.validation.password.length')] |
41
|
|
|
protected string $password; |
42
|
|
|
protected ?string $name = null; |
43
|
|
|
protected string $confirmationCode; |
44
|
|
|
protected \DateTime $createdAt; |
45
|
|
|
protected ?\DateTime $activatedAt; |
46
|
|
|
protected ?\DateTime $deactivatedAt; |
47
|
|
|
protected ?\DateTimeInterface $deletedAt; |
48
|
|
|
protected bool $isConfirmed = false; |
49
|
|
|
protected $isDeleted = false; |
50
|
|
|
protected $roles = []; |
51
|
|
|
protected bool $enabled = false; |
52
|
|
|
|
53
|
|
|
public function getId() |
54
|
|
|
{ |
55
|
|
|
return $this->id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function setId($id): void |
59
|
|
|
{ |
60
|
|
|
$this->id = $id; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getEmail(): string |
64
|
|
|
{ |
65
|
|
|
return $this->email; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setEmail(string $email): void |
69
|
|
|
{ |
70
|
|
|
$this->email = $email; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getPassword(): ?string |
74
|
|
|
{ |
75
|
|
|
return $this->password; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setPassword(string $password): void |
79
|
|
|
{ |
80
|
|
|
$this->password = $password; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setRoles(array $roles): void |
84
|
|
|
{ |
85
|
|
|
$this->roles = $roles; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getRoles(): array |
89
|
|
|
{ |
90
|
|
|
if ($this->roles instanceof Collection) { |
|
|
|
|
91
|
|
|
return $this->roles->toArray(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this->roles; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getSalt() |
98
|
|
|
{ |
99
|
|
|
return null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getUsername() |
103
|
|
|
{ |
104
|
|
|
return $this->getEmail(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function eraseCredentials(): void |
108
|
|
|
{ |
109
|
|
|
$this->password = ''; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getName(): ?string |
113
|
|
|
{ |
114
|
|
|
return $this->name; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function setName(?string $name): void |
118
|
|
|
{ |
119
|
|
|
$this->name = $name; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getConfirmationCode(): string |
123
|
|
|
{ |
124
|
|
|
return $this->confirmationCode; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setConfirmationCode(string $confirmationCode): void |
128
|
|
|
{ |
129
|
|
|
$this->confirmationCode = $confirmationCode; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function isConfirmed(): bool |
133
|
|
|
{ |
134
|
|
|
return $this->isConfirmed; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setIsConfirmed(bool $isConfirmed): void |
138
|
|
|
{ |
139
|
|
|
$this->isConfirmed = $isConfirmed; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function isEqualTo(SymfonyUserInterface $user): bool |
143
|
|
|
{ |
144
|
|
|
if ($this->getUsername() !== $user->getUsername()) { |
|
|
|
|
145
|
|
|
return false; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return true; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getCreatedAt(): \DateTime |
152
|
|
|
{ |
153
|
|
|
return $this->createdAt; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setCreatedAt(\DateTime $createdAt): void |
157
|
|
|
{ |
158
|
|
|
$this->createdAt = $createdAt; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getActivatedAt(): ?\DateTime |
162
|
|
|
{ |
163
|
|
|
return $this->activatedAt; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function setActivatedAt(?\DateTime $activatedAt): void |
167
|
|
|
{ |
168
|
|
|
$this->activatedAt = $activatedAt; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getDeactivatedAt(): ?\DateTime |
172
|
|
|
{ |
173
|
|
|
return $this->deactivatedAt; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function setDeactivatedAt(?\DateTime $deactivatedAt): void |
177
|
|
|
{ |
178
|
|
|
$this->deactivatedAt = $deactivatedAt; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface |
182
|
|
|
{ |
183
|
|
|
$this->deletedAt = $dateTime; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getDeletedAt(): ?\DateTimeInterface |
189
|
|
|
{ |
190
|
|
|
return $this->deletedAt; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function isDeleted(): bool |
194
|
|
|
{ |
195
|
|
|
return $this->isDeleted; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function markAsDeleted(): self |
199
|
|
|
{ |
200
|
|
|
$this->isDeleted = true; |
201
|
|
|
$this->deletedAt = new \DateTime('Now'); |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function unmarkAsDeleted(): self |
207
|
|
|
{ |
208
|
|
|
$this->isDeleted = false; |
209
|
|
|
$this->deletedAt = null; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function getUserIdentifier(): string |
215
|
|
|
{ |
216
|
|
|
return $this->email; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function isEnabled(): bool |
220
|
|
|
{ |
221
|
|
|
return $this->enabled; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function setEnabled(bool $enabled): void |
225
|
|
|
{ |
226
|
|
|
$this->enabled = $enabled; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|