1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright Humbly Arrogant Ltd 2020-2022. |
7
|
|
|
* |
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
9
|
|
|
* |
10
|
|
|
* Change Date: TBD ( 3 years after 2.0.0 release ) |
11
|
|
|
* |
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Parthenon\User\Entity; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
18
|
|
|
use Parthenon\Athena\Entity\DeletableInterface; |
19
|
|
|
use Symfony\Component\Security\Core\User\EquatableInterface; |
20
|
|
|
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; |
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
22
|
|
|
|
23
|
|
|
class User implements UserInterface, EquatableInterface, DeletableInterface |
24
|
|
|
{ |
25
|
|
|
public const DEFAULT_ROLE = 'ROLE_USER'; |
26
|
|
|
protected $id; |
27
|
|
|
/** |
28
|
|
|
* @Assert\NotBlank(message="parthenon.user.validation.email.not_blank") |
29
|
|
|
* @Assert\Email(message="parthenon.user.validation.email.email") |
30
|
|
|
*/ |
31
|
|
|
protected string $email; |
32
|
|
|
/** |
33
|
|
|
* @Assert\NotBlank(message="parthenon.user.validation.password.not_blank") |
34
|
|
|
* @Assert\Length(min="8", minMessage="parthenon.user.validation.password.length") |
35
|
|
|
*/ |
36
|
|
|
protected string $password; |
37
|
|
|
protected ?string $name = null; |
38
|
|
|
protected string $confirmationCode; |
39
|
|
|
protected \DateTime $createdAt; |
40
|
|
|
protected ?\DateTime $activatedAt; |
41
|
|
|
protected ?\DateTime $deactivatedAt; |
42
|
|
|
protected ?\DateTimeInterface $deletedAt; |
43
|
|
|
protected bool $isConfirmed = false; |
44
|
|
|
protected $isDeleted = false; |
45
|
|
|
protected $roles = []; |
46
|
|
|
|
47
|
|
|
public function getId() |
48
|
|
|
{ |
49
|
|
|
return $this->id; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function setId($id): void |
53
|
|
|
{ |
54
|
|
|
$this->id = $id; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getEmail(): string |
58
|
|
|
{ |
59
|
|
|
return $this->email; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setEmail(string $email): void |
63
|
|
|
{ |
64
|
|
|
$this->email = $email; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getPassword(): ?string |
68
|
|
|
{ |
69
|
|
|
return $this->password; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setPassword(string $password): void |
73
|
|
|
{ |
74
|
|
|
$this->password = $password; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setRoles(array $roles): void |
78
|
|
|
{ |
79
|
|
|
$this->roles = $roles; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getRoles(): array |
83
|
|
|
{ |
84
|
|
|
if ($this->roles instanceof Collection) { |
|
|
|
|
85
|
|
|
return $this->roles->toArray(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->roles; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getSalt() |
95
|
|
|
{ |
96
|
|
|
return null; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function getUsername() |
103
|
|
|
{ |
104
|
|
|
return $this->getEmail(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function eraseCredentials() |
111
|
|
|
{ |
112
|
|
|
$this->password = ''; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getName(): ?string |
116
|
|
|
{ |
117
|
|
|
return $this->name; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function setName(?string $name): void |
121
|
|
|
{ |
122
|
|
|
$this->name = $name; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getConfirmationCode(): string |
126
|
|
|
{ |
127
|
|
|
return $this->confirmationCode; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setConfirmationCode(string $confirmationCode): void |
131
|
|
|
{ |
132
|
|
|
$this->confirmationCode = $confirmationCode; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function isConfirmed(): bool |
136
|
|
|
{ |
137
|
|
|
return $this->isConfirmed; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function setIsConfirmed(bool $isConfirmed): void |
141
|
|
|
{ |
142
|
|
|
$this->isConfirmed = $isConfirmed; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function isEqualTo(SymfonyUserInterface $user): bool |
149
|
|
|
{ |
150
|
|
|
if ($this->getUsername() !== $user->getUsername()) { |
|
|
|
|
151
|
|
|
return false; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return true; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getCreatedAt(): \DateTime |
158
|
|
|
{ |
159
|
|
|
return $this->createdAt; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setCreatedAt(\DateTime $createdAt): void |
163
|
|
|
{ |
164
|
|
|
$this->createdAt = $createdAt; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getActivatedAt(): ?\DateTime |
168
|
|
|
{ |
169
|
|
|
return $this->activatedAt; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function setActivatedAt(?\DateTime $activatedAt): void |
173
|
|
|
{ |
174
|
|
|
$this->activatedAt = $activatedAt; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getDeactivatedAt(): ?\DateTime |
178
|
|
|
{ |
179
|
|
|
return $this->deactivatedAt; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function setDeactivatedAt(?\DateTime $deactivatedAt): void |
183
|
|
|
{ |
184
|
|
|
$this->deactivatedAt = $deactivatedAt; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface |
188
|
|
|
{ |
189
|
|
|
$this->deletedAt = $dateTime; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function getDeletedAt(): ?\DateTimeInterface |
195
|
|
|
{ |
196
|
|
|
return $this->deletedAt; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function isDeleted(): bool |
200
|
|
|
{ |
201
|
|
|
return $this->isDeleted; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function markAsDeleted(): self |
205
|
|
|
{ |
206
|
|
|
$this->isDeleted = true; |
207
|
|
|
$this->deletedAt = new \DateTime('Now'); |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function unmarkAsDeleted(): self |
213
|
|
|
{ |
214
|
|
|
$this->isDeleted = false; |
215
|
|
|
$this->deletedAt = null; |
216
|
|
|
|
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getUserIdentifier(): string |
221
|
|
|
{ |
222
|
|
|
return $this->email; |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|