1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\Attribute\Accessor as EntityAccessor; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Ds\Component\Model\Type\Deletable; |
8
|
|
|
use Ds\Component\Model\Type\Identifiable; |
9
|
|
|
use Ds\Component\Model\Type\Uuidentifiable; |
10
|
|
|
use Ds\Component\Model\Type\Ownable; |
11
|
|
|
use Ds\Component\Model\Type\Identitiable; |
12
|
|
|
use Ds\Component\Model\Type\Versionable; |
13
|
|
|
use Ds\Component\Model\Attribute\Accessor; |
14
|
|
|
use Ds\Component\Security\Model\Type\Secured; |
15
|
|
|
use Ds\Component\Tenant\Model\Attribute\Accessor as TenantAccessor; |
16
|
|
|
use Ds\Component\Tenant\Model\Type\Tenantable; |
17
|
|
|
use FOS\UserBundle\Model\User as BaseUser; |
18
|
|
|
use FOS\UserBundle\Model\UserInterface; |
19
|
|
|
use Knp\DoctrineBehaviors\Model as Behavior; |
20
|
|
|
|
21
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
22
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
23
|
|
|
use Doctrine\ORM\Mapping as ORM; |
24
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as ORMAssert; |
25
|
|
|
use Symfony\Component\Serializer\Annotation As Serializer; |
26
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @ApiResource( |
30
|
|
|
* attributes={ |
31
|
|
|
* "normalization_context"={ |
32
|
|
|
* "groups"={"user_output"} |
33
|
|
|
* }, |
34
|
|
|
* "denormalization_context"={ |
35
|
|
|
* "groups"={"user_input"} |
36
|
|
|
* }, |
37
|
|
|
* "filters"={ |
38
|
|
|
* "app.user.search", |
39
|
|
|
* "app.user.date", |
40
|
|
|
* "app.user.boolean", |
41
|
|
|
* "app.user.order" |
42
|
|
|
* } |
43
|
|
|
* } |
44
|
|
|
* ) |
45
|
|
|
* @ORM\Entity |
46
|
|
|
* @ORM\Table( |
47
|
|
|
* name="app_user", |
48
|
|
|
* uniqueConstraints={ |
49
|
|
|
* @ORM\UniqueConstraint(columns={"username", "tenant"}), |
50
|
|
|
* @ORM\UniqueConstraint(columns={"username_canonical", "tenant"}), |
51
|
|
|
* @ORM\UniqueConstraint(columns={"email", "tenant"}), |
52
|
|
|
* @ORM\UniqueConstraint(columns={"email_canonical", "tenant"}) |
53
|
|
|
* } |
54
|
|
|
* ) |
55
|
|
|
* @ORM\AttributeOverrides({ |
56
|
|
|
* @ORM\AttributeOverride( |
57
|
|
|
* name="usernameCanonical", |
58
|
|
|
* column=@ORM\Column(type="string", name="username_canonical", length=180, unique=false) |
59
|
|
|
* ), |
60
|
|
|
* @ORM\AttributeOverride( |
61
|
|
|
* name="emailCanonical", |
62
|
|
|
* column=@ORM\Column(type="string", name="email_canonical", length=180, unique=false) |
63
|
|
|
* ) |
64
|
|
|
* }) |
65
|
|
|
* @ORM\Cache(usage="NONSTRICT_READ_WRITE") |
66
|
|
|
* @ORMAssert\UniqueEntity(fields="uuid") |
67
|
|
|
* @ORMAssert\UniqueEntity(fields={"username", "tenant"}) |
68
|
|
|
* @ORMAssert\UniqueEntity(fields={"usernameCanonical", "tenant"}) |
69
|
|
|
* @ORMAssert\UniqueEntity(fields={"email", "tenant"}) |
70
|
|
|
* @ORMAssert\UniqueEntity(fields={"emailCanonical", "tenant"}) |
71
|
|
|
*/ |
72
|
|
|
class User extends BaseUser implements Identifiable, Uuidentifiable, Ownable, Identitiable, Deletable, Versionable, Tenantable, Secured |
73
|
|
|
{ |
74
|
|
|
use Behavior\Timestampable\Timestampable; |
75
|
|
|
use Behavior\SoftDeletable\SoftDeletable; |
76
|
|
|
|
77
|
|
|
use Accessor\Id; |
78
|
|
|
use Accessor\Uuid; |
79
|
|
|
use EntityAccessor\OAuths; |
80
|
|
|
use Accessor\Owner; |
81
|
|
|
use Accessor\OwnerUuid; |
82
|
|
|
use Accessor\Identity; |
83
|
|
|
use Accessor\IdentityUuid; |
84
|
|
|
use EntityAccessor\Registration; |
85
|
|
|
use Accessor\Deleted; |
86
|
|
|
use Accessor\Version; |
87
|
|
|
use TenantAccessor\Tenant; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var integer |
91
|
|
|
* @ApiProperty(identifier=false, writable=false) |
92
|
|
|
* @Serializer\Groups({"user_output"}) |
93
|
|
|
* @ORM\Id |
94
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
95
|
|
|
* @ORM\Column(name="id", type="integer") |
96
|
|
|
*/ |
97
|
|
|
protected $id; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var string |
101
|
|
|
* @ApiProperty(identifier=true, writable=false) |
102
|
|
|
* @Serializer\Groups({"user_output"}) |
103
|
|
|
* @ORM\Column(name="uuid", type="guid", unique=true) |
104
|
|
|
* @Assert\Uuid |
105
|
|
|
*/ |
106
|
|
|
protected $uuid; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var \DateTime |
110
|
|
|
* @ApiProperty(writable=false) |
111
|
|
|
* @Serializer\Groups({"user_output"}) |
112
|
|
|
*/ |
113
|
|
|
protected $createdAt; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var \DateTime |
117
|
|
|
* @ApiProperty(writable=false) |
118
|
|
|
* @Serializer\Groups({"user_output"}) |
119
|
|
|
*/ |
120
|
|
|
protected $updatedAt; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var \DateTime |
124
|
|
|
* @ApiProperty(writable=false) |
125
|
|
|
* @Serializer\Groups({"user_output"}) |
126
|
|
|
*/ |
127
|
|
|
protected $deletedAt; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var string |
131
|
|
|
* @ApiProperty |
132
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
133
|
|
|
* @Assert\NotBlank |
134
|
|
|
* @Assert\Length(min=1, max=255) |
135
|
|
|
*/ |
136
|
|
|
protected $username; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @var string |
140
|
|
|
* @ApiProperty(readable=false) |
141
|
|
|
* @Serializer\Groups({"user_input"}) |
142
|
|
|
*/ |
143
|
|
|
protected $plainPassword; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var string |
147
|
|
|
* @ApiProperty |
148
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
149
|
|
|
* @Assert\NotBlank |
150
|
|
|
* @Assert\Length(min=1, max=255) |
151
|
|
|
* @Assert\Regex("/^.+@.+$/") |
152
|
|
|
*/ |
153
|
|
|
protected $email; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var \Doctrine\Common\Collections\ArrayCollection |
157
|
|
|
* @ApiProperty(writable=false) |
158
|
|
|
* @Serializer\Groups({"user_output"}) |
159
|
|
|
* @ORM\OneToMany(targetEntity="OAuth", mappedBy="user") |
160
|
|
|
* @ORM\Cache(usage="NONSTRICT_READ_WRITE") |
161
|
|
|
*/ |
162
|
|
|
protected $oauths; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @var boolean |
166
|
|
|
* @ApiProperty |
167
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
168
|
|
|
* @Assert\Type("boolean") |
169
|
|
|
*/ |
170
|
|
|
protected $enabled; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @var \DateTime |
174
|
|
|
* @ApiProperty(writable=false) |
175
|
|
|
* @Serializer\Groups({"user_output"}) |
176
|
|
|
*/ |
177
|
|
|
protected $lastLogin; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @var \Doctrine\Common\Collections\Collection |
181
|
|
|
* @ApiProperty |
182
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
183
|
|
|
*/ |
184
|
|
|
protected $groups; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @var array |
188
|
|
|
* @ApiProperty |
189
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
190
|
|
|
* @Assert\Type("array") |
191
|
|
|
* @Assert\All({ |
192
|
|
|
* @Assert\NotBlank, |
193
|
|
|
* @Assert\Length(min=1) |
194
|
|
|
* }) |
195
|
|
|
*/ |
196
|
|
|
protected $roles; |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @var string |
200
|
|
|
* @ApiProperty |
201
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
202
|
|
|
* @ORM\Column(name="`owner`", type="string", length=255, nullable=true) |
203
|
|
|
* @Assert\NotBlank |
204
|
|
|
* @Assert\Length(min=1, max=255) |
205
|
|
|
*/ |
206
|
|
|
protected $owner; |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @var string |
210
|
|
|
* @ApiProperty |
211
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
212
|
|
|
* @ORM\Column(name="owner_uuid", type="guid", nullable=true) |
213
|
|
|
* @Assert\NotBlank |
214
|
|
|
* @Assert\Uuid |
215
|
|
|
*/ |
216
|
|
|
protected $ownerUuid; |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @var string |
220
|
|
|
* @ApiProperty |
221
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
222
|
|
|
* @ORM\Column(name="identity", type="string", length=255, nullable=true) |
223
|
|
|
* @Assert\NotBlank |
224
|
|
|
* @Assert\Length(min=1, max=255) |
225
|
|
|
*/ |
226
|
|
|
protected $identity; |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @var string |
230
|
|
|
* @ApiProperty |
231
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
232
|
|
|
* @ORM\Column(name="identity_uuid", type="guid", nullable=true) |
233
|
|
|
* @Assert\Uuid |
234
|
|
|
*/ |
235
|
|
|
protected $identityUuid; |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @var \AppBundle\Entity\Registration |
239
|
|
|
* @ORM\OneToOne(targetEntity="Registration", mappedBy="user") |
240
|
|
|
* @ORM\Cache(usage="NONSTRICT_READ_WRITE") |
241
|
|
|
*/ |
242
|
|
|
protected $registration; |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @var integer |
246
|
|
|
* @ApiProperty |
247
|
|
|
* @Serializer\Groups({"user_output", "user_input"}) |
248
|
|
|
* @ORM\Column(name="version", type="integer") |
249
|
|
|
* @ORM\Version |
250
|
|
|
* @Assert\NotBlank |
251
|
|
|
* @Assert\Type("integer") |
252
|
|
|
*/ |
253
|
|
|
protected $version; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @var string |
257
|
|
|
* @ApiProperty(writable=false) |
258
|
|
|
* @Serializer\Groups({"user_output"}) |
259
|
|
|
* @ORM\Column(name="tenant", type="guid") |
260
|
|
|
* @Assert\Uuid |
261
|
|
|
*/ |
262
|
|
|
protected $tenant; |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Check if user is user |
266
|
|
|
* |
267
|
|
|
* @param \FOS\UserBundle\Model\UserInterface $user |
268
|
|
|
* @return boolean |
269
|
|
|
*/ |
270
|
|
|
public function isUser(UserInterface $user = null) |
271
|
|
|
{ |
272
|
|
|
return $user instanceof self && $user->id === $this->id; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Constructor |
277
|
|
|
*/ |
278
|
|
|
public function __construct() |
279
|
|
|
{ |
280
|
|
|
parent::__construct(); |
281
|
|
|
$this->oauths = new ArrayCollection; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|