Completed
Push — 7.5 ( faf482...14c55e )
by
unknown
191:03 queued 173:36
created

UserService::checkUserCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the UserService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\REST\Client;
10
11
use DateTimeInterface;
12
use eZ\Publish\API\Repository\UserService as APIUserService;
13
use eZ\Publish\API\Repository\Values\Content\Content;
14
use eZ\Publish\API\Repository\Values\User\PasswordInfo;
15
use eZ\Publish\API\Repository\Values\User\PasswordValidationContext;
16
use eZ\Publish\API\Repository\Values\User\User;
17
use eZ\Publish\API\Repository\Values\User\UserCreateStruct;
18
use eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct;
19
use eZ\Publish\API\Repository\Values\User\UserUpdateStruct;
20
use eZ\Publish\API\Repository\Values\User\UserGroup;
21
use eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct;
22
use eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct;
23
use eZ\Publish\Core\REST\Common\RequestParser;
24
use eZ\Publish\Core\REST\Common\Input\Dispatcher;
25
use eZ\Publish\Core\REST\Common\Output\Visitor;
26
27
/**
28
 * Implementation of the {@link \eZ\Publish\API\Repository\UserService}
29
 * interface.
30
 *
31
 * @see \eZ\Publish\API\Repository\UserService
32
 */
33
class UserService implements APIUserService, Sessionable
34
{
35
    /** @var \eZ\Publish\Core\REST\Client\HttpClient */
36
    private $client;
37
38
    /** @var \eZ\Publish\Core\REST\Common\Input\Dispatcher */
39
    private $inputDispatcher;
40
41
    /** @var \eZ\Publish\Core\REST\Common\Output\Visitor */
42
    private $outputVisitor;
43
44
    /** @var \eZ\Publish\Core\REST\Common\RequestParser */
45
    private $requestParser;
46
47
    /**
48
     * @param \eZ\Publish\Core\REST\Client\HttpClient $client
49
     * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher
50
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor
51
     * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser
52
     */
53
    public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)
54
    {
55
        $this->client = $client;
56
        $this->inputDispatcher = $inputDispatcher;
57
        $this->outputVisitor = $outputVisitor;
58
        $this->requestParser = $requestParser;
59
    }
60
61
    /**
62
     * Set session ID.
63
     *
64
     * Only for testing
65
     *
66
     * @param mixed tringid
67
     *
68
     * @private
69
     */
70
    public function setSession($id)
71
    {
72
        if ($this->outputVisitor instanceof Sessionable) {
73
            $this->outputVisitor->setSession($id);
74
        }
75
    }
76
77
    /**
78
     * Creates a new user group using the data provided in the ContentCreateStruct parameter.
79
     *
80
     * In 4.x in the content type parameter in the profile is ignored
81
     * - the content type is determined via configuration and can be set to null.
82
     * The returned version is published.
83
     *
84
     * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group
85
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup
86
     *
87
     * @return \eZ\Publish\API\Repository\Values\User\UserGroup
88
     *
89
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group
90
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the input structure has invalid data
91
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid
92
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing
93
     */
94
    public function createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup)
95
    {
96
        throw new \Exception('@todo: Implement.');
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function loadUserGroup($id, array $prioritizedLanguages = [])
103
    {
104
        throw new \Exception('@todo: Implement.');
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function loadSubUserGroups(UserGroup $userGroup, $offset = 0, $limit = 25, array $prioritizedLanguages = [])
111
    {
112
        throw new \Exception('@todo: Implement.');
113
    }
114
115
    /**
116
     * Removes a user group.
117
     *
118
     * the users which are not assigned to other groups will be deleted.
119
     *
120
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
121
     *
122
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group
123
     */
124
    public function deleteUserGroup(UserGroup $userGroup)
125
    {
126
        throw new \Exception('@todo: Implement.');
127
    }
128
129
    /**
130
     * Moves the user group to another parent.
131
     *
132
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
133
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $newParent
134
     *
135
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group
136
     */
137
    public function moveUserGroup(UserGroup $userGroup, UserGroup $newParent)
138
    {
139
        throw new \Exception('@todo: Implement.');
140
    }
141
142
    /**
143
     * Updates the group profile with fields and meta data.
144
     *
145
     * 4.x: If the versionUpdateStruct is set in $userGroupUpdateStruct, this method internally creates a content draft, updates ts with the provided data
146
     * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.
147
     *
148
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
149
     * @param \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct $userGroupUpdateStruct
150
     *
151
     * @return \eZ\Publish\API\Repository\Values\User\UserGroup
152
     *
153
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group
154
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupUpdateStruct is not valid
155
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty
156
     */
157
    public function updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct)
158
    {
159
        throw new \Exception('@todo: Implement.');
160
    }
161
162
    /**
163
     * Create a new user. The created user is published by this method.
164
     *
165
     * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user
166
     * @param array $parentGroups the groups of type {@link \eZ\Publish\API\Repository\Values\User\UserGroup} which are assigned to the user after creation
167
     *
168
     * @return \eZ\Publish\API\Repository\Values\User\User
169
     *
170
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group
171
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user group was not found
172
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid
173
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing
174
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a user with provided login already exists
175
     */
176
    public function createUser(UserCreateStruct $userCreateStruct, array $parentGroups)
177
    {
178
        throw new \Exception('@todo: Implement.');
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function loadUser($userId, array $prioritizedLanguages = [])
185
    {
186
        throw new \Exception('@todo: Implement.');
187
    }
188
189
    /**
190
     * Loads anonymous user.
191
     *
192
     * @deprecated since 5.3, use loadUser( $anonymousUserId ) instead
193
     *
194
     *
195
     * @return \eZ\Publish\API\Repository\Values\User\User
196
     */
197
    public function loadAnonymousUser()
198
    {
199
        throw new \Exception('@todo: Implement.');
200
    }
201
202
    /**
203
     * {@inheritdoc}
204
     */
205
    public function loadUserByCredentials($login, $password, array $prioritizedLanguages = [])
206
    {
207
        throw new \Exception('@todo: Implement.');
208
    }
209
210
    /**
211
     * {@inheritdoc}
212
     */
213
    public function checkUserCredentials(User $user, string $credentials): bool
214
    {
215
        throw new \Exception('@todo: Implement.');
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221
    public function loadUserByLogin($login, array $prioritizedLanguages = [])
222
    {
223
        throw new \Exception('@todo: Implement.');
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229
    public function loadUsersByEmail($email, array $prioritizedLanguages = [])
230
    {
231
        throw new \Exception('@todo: Implement.');
232
    }
233
234
    /**
235
     * Loads a user with user hash key.
236
     *
237
     * @param string $hash
238
     * @param array $prioritizedLanguages
239
     *
240
     * @return \eZ\Publish\API\Repository\Values\User\User
241
     */
242
    public function loadUserByToken($hash, array $prioritizedLanguages = [])
243
    {
244
        throw new \Exception('@todo: Implement.');
245
    }
246
247
    /**
248
     * This method deletes a user.
249
     *
250
     * @param \eZ\Publish\API\Repository\Values\User\User $user
251
     *
252
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user
253
     */
254
    public function deleteUser(User $user)
255
    {
256
        throw new \Exception('@todo: Implement.');
257
    }
258
259
    /**
260
     * Updates a user.
261
     *
262
     * 4.x: If the versionUpdateStruct is set in the user update structure, this method internally creates a content draft, updates ts with the provided data
263
     * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.
264
     *
265
     * @param \eZ\Publish\API\Repository\Values\User\User $user
266
     * @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct
267
     *
268
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user
269
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid
270
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty
271
     *
272
     * @return \eZ\Publish\API\Repository\Values\User\User
273
     */
274
    public function updateUser(User $user, UserUpdateStruct $userUpdateStruct)
275
    {
276
        throw new \Exception('@todo: Implement.');
277
    }
278
279
    /**
280
     * Update the user token information specified by the user token struct.
281
     *
282
     * @param \eZ\Publish\API\Repository\Values\User\User $user
283
     * @param \eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct $userTokenUpdateStruct
284
     *
285
     * @return \eZ\Publish\API\Repository\Values\User\User
286
     */
287
    public function updateUserToken(User $user, UserTokenUpdateStruct $userTokenUpdateStruct)
288
    {
289
        throw new \Exception('@todo: Implement.');
290
    }
291
292
    /**
293
     * Expires user token with user hash.
294
     *
295
     * @param string $hash
296
     */
297
    public function expireUserToken($hash)
298
    {
299
        throw new \Exception('@todo: Implement.');
300
    }
301
302
303
    /**
304
     * Assigns a new user group to the user.
305
     *
306
     * @param \eZ\Publish\API\Repository\Values\User\User $user
307
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
308
     *
309
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign the user group to the user
310
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group
311
     */
312
    public function assignUserToUserGroup(User $user, UserGroup $userGroup)
313
    {
314
        throw new \Exception('@todo: Implement.');
315
    }
316
317
    /**
318
     * Removes a user group from the user.
319
     *
320
     * @param \eZ\Publish\API\Repository\Values\User\User $user
321
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
322
     *
323
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user
324
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group
325
     */
326
    public function unAssignUserFromUserGroup(User $user, UserGroup $userGroup)
327
    {
328
        throw new \Exception('@todo: Implement.');
329
    }
330
331
    /**
332
     * {@inheritdoc}
333
     */
334
    public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25, array $prioritizedLanguages = [])
335
    {
336
        throw new \Exception('@todo: Implement.');
337
    }
338
339
    /**
340
     * {@inheritdoc}
341
     */
342
    public function loadUsersOfUserGroup(
343
        UserGroup $userGroup,
344
        $offset = 0,
345
        $limit = 25,
346
        array $prioritizedLanguages = []
347
    ) {
348
        throw new \Exception('@todo: Implement.');
349
    }
350
351
    /**
352
     * {@inheritdoc}
353
     */
354
    public function isUser(Content $content): bool
355
    {
356
        foreach ($content->getFields() as $field) {
357
            if ($field->fieldTypeIdentifier === 'ezuser') {
358
                return true;
359
            }
360
        }
361
362
        return false;
363
    }
364
365
    /**
366
     * {@inheritdoc}
367
     */
368
    public function isUserGroup(Content $content): bool
369
    {
370
        // TODO: Need a way to identify user groups her. Config is an option, lookup another but not an ideal solution.
371
        return false;
372
    }
373
374
    /**
375
     * Instantiate a user create class.
376
     *
377
     * @param string $login the login of the new user
378
     * @param string $email the email of the new user
379
     * @param string $password the plain password of the new user
380
     * @param string $mainLanguageCode the main language for the underlying content object
381
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration
382
     *
383
     * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
384
     */
385
    public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null)
386
    {
387
        throw new \Exception('@todo: Implement.');
388
    }
389
390
    /**
391
     * Instantiate a user group create class.
392
     *
393
     * @param string $mainLanguageCode The main language for the underlying content object
394
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration
395
     *
396
     * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct
397
     */
398
    public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null)
399
    {
400
        throw new \Exception('@todo: Implement.');
401
    }
402
403
    /**
404
     * Instantiate a new user update struct.
405
     *
406
     * @return \eZ\Publish\API\Repository\Values\User\UserUpdateStruct
407
     */
408
    public function newUserUpdateStruct()
409
    {
410
        throw new \Exception('@todo: Implement.');
411
    }
412
413
    /**
414
     * Instantiate a new user group update struct.
415
     *
416
     * @return \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct
417
     */
418
    public function newUserGroupUpdateStruct()
419
    {
420
        throw new \Exception('@todo: Implement.');
421
    }
422
423
    /**
424
     * {@inheritdoc}
425
     */
426
    public function validatePassword(string $password, PasswordValidationContext $context = null): array
427
    {
428
        throw new \Exception('@todo: Implement.');
429
    }
430
431
    public function getPasswordInfo(User $user): PasswordInfo
432
    {
433
        throw new \Exception('@todo: Implement.');
434
    }
435
}
436