1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Entity; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
|
|
|
6
|
|
|
use ApiPlatform\Metadata\Get; |
|
|
|
|
7
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
|
|
|
8
|
|
|
use ApiPlatform\Metadata\ApiProperty; |
|
|
|
|
9
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
|
|
|
|
10
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
|
|
|
|
11
|
|
|
use ApiPlatform\Metadata\Post; |
|
|
|
|
12
|
|
|
use ApiPlatform\Metadata\Put; |
|
|
|
|
13
|
|
|
use ApiPlatform\Metadata\Delete; |
|
|
|
|
14
|
|
|
use ControleOnline\Controller\ChangeApiKeyAction; |
15
|
|
|
use ControleOnline\Controller\ChangePasswordAction; |
16
|
|
|
use ControleOnline\Controller\CreateUserAction; |
17
|
|
|
use ControleOnline\Controller\Oauth\GoogleConnectController; |
18
|
|
|
use ControleOnline\Controller\Oauth\GoogleReturnController; |
19
|
|
|
use ControleOnline\Controller\Oauth\MercadolivreReturnController; |
20
|
|
|
use ControleOnline\Controller\SecurityController; |
21
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
22
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
|
|
|
23
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
|
|
|
24
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
|
|
|
25
|
|
|
use Doctrine\Common\Collections\Collection; |
|
|
|
|
26
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* User |
30
|
|
|
* |
31
|
|
|
* @ORM\EntityListeners ({ControleOnline\Listener\LogListener::class}) |
32
|
|
|
* @ORM\Entity (repositoryClass="ControleOnline\Repository\UserRepository") |
33
|
|
|
* @ORM\Table (name="users", uniqueConstraints={@ORM\UniqueConstraint (name="user_name", columns={"username"}), @ORM\UniqueConstraint(name="api_key", columns={"api_key"})}, indexes={@ORM\Index (name="people_id", columns={"people_id"})}) |
34
|
|
|
* @ORM\HasLifecycleCallbacks |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
#[ApiResource( |
40
|
|
|
operations: [ |
41
|
|
|
new GetCollection( |
42
|
|
|
security: 'is_granted(\'ROLE_CLIENT\')', |
43
|
|
|
uriTemplate: '/oauth/google/connect', |
44
|
|
|
controller: GoogleConnectController::class, |
45
|
|
|
), |
46
|
|
|
new GetCollection( |
47
|
|
|
security: 'is_granted(\'ROLE_CLIENT\')', |
48
|
|
|
uriTemplate: '/oauth/google/return', |
49
|
|
|
controller: GoogleReturnController::class, |
50
|
|
|
), |
51
|
|
|
new GetCollection( |
52
|
|
|
security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')', |
53
|
|
|
uriTemplate: '/oauth/mercadolivre/return', |
54
|
|
|
controller: MercadolivreReturnController::class, |
55
|
|
|
), |
56
|
|
|
new Post( |
57
|
|
|
uriTemplate: '/oauth/google/return', |
58
|
|
|
controller: GoogleReturnController::class, |
59
|
|
|
securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')', |
60
|
|
|
), |
61
|
|
|
new Post( |
62
|
|
|
uriTemplate: '/users', |
63
|
|
|
controller: CreateUserAction::class, |
64
|
|
|
securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')', |
65
|
|
|
), |
66
|
|
|
new Delete(security: 'is_granted(\'ROLE_CLIENT\')'), |
67
|
|
|
|
68
|
|
|
new Put( |
69
|
|
|
uriTemplate: '/users/{id}/change-api-key', |
70
|
|
|
controller: ChangeApiKeyAction::class, |
71
|
|
|
securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')', |
72
|
|
|
), |
73
|
|
|
new Put( |
74
|
|
|
uriTemplate: '/users/{id}/change-password', |
75
|
|
|
controller: ChangePasswordAction::class, |
76
|
|
|
securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')', |
77
|
|
|
), |
78
|
|
|
new Post( |
79
|
|
|
uriTemplate: '/token', |
80
|
|
|
controller: SecurityController::class, |
81
|
|
|
securityPostDenormalize: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')', |
82
|
|
|
), |
83
|
|
|
new Get(security: 'is_granted(\'ROLE_CLIENT\')'), |
84
|
|
|
new GetCollection(security: 'is_granted(\'ROLE_CLIENT\')') |
85
|
|
|
], |
86
|
|
|
formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']], |
87
|
|
|
normalizationContext: ['groups' => ['user_read']], |
88
|
|
|
denormalizationContext: ['groups' => ['user_write']] |
89
|
|
|
)] |
90
|
|
|
#[ApiFilter(filterClass: SearchFilter::class, properties: ['people' => 'exact'])] |
91
|
|
|
class User implements UserInterface |
92
|
|
|
{ |
93
|
|
|
/** |
94
|
|
|
* @ORM\Id() |
95
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
96
|
|
|
* @ORM\Column(type="integer") |
97
|
|
|
* @Groups({"people_read", "user_read"}) |
98
|
|
|
*/ |
99
|
|
|
private $id; |
100
|
|
|
/** |
101
|
|
|
* |
102
|
|
|
* @ORM\Column(type="string", length=50, nullable=false) |
103
|
|
|
* @Groups({"people_read", "user_read"}) |
104
|
|
|
*/ |
105
|
|
|
private $username; |
106
|
|
|
/** |
107
|
|
|
* |
108
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
109
|
|
|
*/ |
110
|
|
|
private $hash; |
111
|
|
|
/** |
112
|
|
|
* |
113
|
|
|
* @ORM\Column(type="string", length=60, nullable=true) |
114
|
|
|
*/ |
115
|
|
|
private $oauthUser; |
116
|
|
|
/** |
117
|
|
|
* |
118
|
|
|
* @ORM\Column(type="string", length=60, nullable=true) |
119
|
|
|
*/ |
120
|
|
|
private $oauthHash; |
121
|
|
|
/** |
122
|
|
|
* |
123
|
|
|
* @ORM\Column(type="string", length=60, nullable=true) |
124
|
|
|
*/ |
125
|
|
|
private $lostPassword; |
126
|
|
|
/** |
127
|
|
|
* @ORM\Column(type="string", length=60, nullable=false) |
128
|
|
|
* @Groups({"people_read", "user_read"}) |
129
|
|
|
*/ |
130
|
|
|
private $apiKey; |
131
|
|
|
/** |
132
|
|
|
* @var \ControleOnline\Entity\People |
133
|
|
|
* |
134
|
|
|
* @ORM\ManyToOne(targetEntity="ControleOnline\Entity\People", inversedBy="user") |
135
|
|
|
* @ORM\JoinColumns({ |
136
|
|
|
* @ORM\JoinColumn(name="people_id", referencedColumnName="id", nullable=false) |
137
|
|
|
* }) |
138
|
|
|
* @Groups({"people_read", "user_read"}) |
139
|
|
|
*/ |
140
|
|
|
private $people; |
141
|
|
|
public function __construct() |
142
|
|
|
{ |
143
|
|
|
$this->generateApiKey(); |
144
|
|
|
} |
145
|
|
|
public function getId(): ?int |
146
|
|
|
{ |
147
|
|
|
return $this->id; |
148
|
|
|
} |
149
|
|
|
public function getUsername(): string |
150
|
|
|
{ |
151
|
|
|
return (string) $this->username; |
152
|
|
|
} |
153
|
|
|
public function setUsername(string $username): self |
154
|
|
|
{ |
155
|
|
|
$this->username = $username; |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
/** |
159
|
|
|
* Returns the password used to authenticate the user. |
160
|
|
|
* |
161
|
|
|
* This should be the encoded password. On authentication, a plain-text |
162
|
|
|
* password will be salted, encoded, and then compared to this value. |
163
|
|
|
* |
164
|
|
|
* @return string|null The encoded password if any |
165
|
|
|
*/ |
166
|
|
|
public function getPassword() |
167
|
|
|
{ |
168
|
|
|
return $this->hash; |
169
|
|
|
} |
170
|
|
|
/** |
171
|
|
|
* Returns the roles granted to the user. |
172
|
|
|
* |
173
|
|
|
* public function getRoles() |
174
|
|
|
* { |
175
|
|
|
* return ['ROLE_USER']; |
176
|
|
|
* } |
177
|
|
|
* |
178
|
|
|
* Alternatively, the roles might be stored on a ``roles`` property, |
179
|
|
|
* and populated in any number of different ways when the user object |
180
|
|
|
* is created. |
181
|
|
|
* |
182
|
|
|
* @return string[] The user roles |
183
|
|
|
*/ |
184
|
|
|
public function getRoles() |
185
|
|
|
{ |
186
|
|
|
return ['ROLE_CLIENT']; |
187
|
|
|
} |
188
|
|
|
/** |
189
|
|
|
* @see UserInterface |
190
|
|
|
*/ |
191
|
|
|
public function getSalt() |
192
|
|
|
{ |
193
|
|
|
// not needed when using the "bcrypt" algorithm in security.yaml |
194
|
|
|
} |
195
|
|
|
/** |
196
|
|
|
* @see UserInterface |
197
|
|
|
*/ |
198
|
|
|
public function eraseCredentials() |
199
|
|
|
{ |
200
|
|
|
// If you store any temporary, sensitive data on the user, clear it here |
201
|
|
|
// $this->plainPassword = null; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function generateApiKey(): string |
205
|
|
|
{ |
206
|
|
|
$this->apiKey = md5($this->getUsername() . microtime()); |
207
|
|
|
return $this->apiKey; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getApiKey(): string |
211
|
|
|
{ |
212
|
|
|
return $this->apiKey; |
213
|
|
|
} |
214
|
|
|
public function setHash($hash): self |
215
|
|
|
{ |
216
|
|
|
$this->hash = $hash; |
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
public function getHash(): string |
220
|
|
|
{ |
221
|
|
|
return $this->hash; |
222
|
|
|
} |
223
|
|
|
public function getOauthHash(): string |
224
|
|
|
{ |
225
|
|
|
return $this->oauthHash; |
|
|
|
|
226
|
|
|
} |
227
|
|
|
public function setOauthHash($hash): self |
228
|
|
|
{ |
229
|
|
|
$this->oauthHash = $hash; |
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
public function setOauthUser($user): self |
233
|
|
|
{ |
234
|
|
|
$this->oauthUser = $user; |
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
public function getOauthUser(): string |
238
|
|
|
{ |
239
|
|
|
return $this->oauthUser; |
|
|
|
|
240
|
|
|
} |
241
|
|
|
public function setPeople(People $people = null): self |
242
|
|
|
{ |
243
|
|
|
$this->people = $people; |
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
public function getPeople(): People |
247
|
|
|
{ |
248
|
|
|
return $this->people; |
249
|
|
|
} |
250
|
|
|
public function setLostPassword(?string $hash): self |
251
|
|
|
{ |
252
|
|
|
$this->lostPassword = $hash; |
253
|
|
|
return $this; |
254
|
|
|
} |
255
|
|
|
public function getLostPassword(): ?string |
256
|
|
|
{ |
257
|
|
|
return $this->lostPassword; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
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