Completed
Push — ezp_30797 ( 8198f2...1e476a )
by
unknown
18:51
created

UserService::getPasswordInfo()   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 1
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 loadUserByLogin($login, array $prioritizedLanguages = [])
214
    {
215
        throw new \Exception('@todo: Implement.');
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221
    public function loadUsersByEmail($email, array $prioritizedLanguages = [])
222
    {
223
        throw new \Exception('@todo: Implement.');
224
    }
225
226
    /**
227
     * Loads a user with user hash key.
228
     *
229
     * @param string $hash
230
     * @param array $prioritizedLanguages
231
     *
232
     * @return \eZ\Publish\API\Repository\Values\User\User
233
     */
234
    public function loadUserByToken($hash, array $prioritizedLanguages = [])
235
    {
236
        throw new \Exception('@todo: Implement.');
237
    }
238
239
    /**
240
     * This method deletes a user.
241
     *
242
     * @param \eZ\Publish\API\Repository\Values\User\User $user
243
     *
244
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user
245
     */
246
    public function deleteUser(User $user)
247
    {
248
        throw new \Exception('@todo: Implement.');
249
    }
250
251
    /**
252
     * Updates a user.
253
     *
254
     * 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
255
     * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.
256
     *
257
     * @param \eZ\Publish\API\Repository\Values\User\User $user
258
     * @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct
259
     *
260
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user
261
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid
262
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty
263
     *
264
     * @return \eZ\Publish\API\Repository\Values\User\User
265
     */
266
    public function updateUser(User $user, UserUpdateStruct $userUpdateStruct)
267
    {
268
        throw new \Exception('@todo: Implement.');
269
    }
270
271
    /**
272
     * Update the user token information specified by the user token struct.
273
     *
274
     * @param \eZ\Publish\API\Repository\Values\User\User $user
275
     * @param \eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct $userTokenUpdateStruct
276
     *
277
     * @return \eZ\Publish\API\Repository\Values\User\User
278
     */
279
    public function updateUserToken(User $user, UserTokenUpdateStruct $userTokenUpdateStruct)
280
    {
281
        throw new \Exception('@todo: Implement.');
282
    }
283
284
    /**
285
     * Expires user token with user hash.
286
     *
287
     * @param string $hash
288
     */
289
    public function expireUserToken($hash)
290
    {
291
        throw new \Exception('@todo: Implement.');
292
    }
293
294
295
    /**
296
     * Assigns a new user group to the user.
297
     *
298
     * @param \eZ\Publish\API\Repository\Values\User\User $user
299
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
300
     *
301
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign the user group to the user
302
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group
303
     */
304
    public function assignUserToUserGroup(User $user, UserGroup $userGroup)
305
    {
306
        throw new \Exception('@todo: Implement.');
307
    }
308
309
    /**
310
     * Removes a user group from the user.
311
     *
312
     * @param \eZ\Publish\API\Repository\Values\User\User $user
313
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
314
     *
315
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user
316
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group
317
     */
318
    public function unAssignUserFromUserGroup(User $user, UserGroup $userGroup)
319
    {
320
        throw new \Exception('@todo: Implement.');
321
    }
322
323
    /**
324
     * {@inheritdoc}
325
     */
326
    public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25, array $prioritizedLanguages = [])
327
    {
328
        throw new \Exception('@todo: Implement.');
329
    }
330
331
    /**
332
     * {@inheritdoc}
333
     */
334
    public function loadUsersOfUserGroup(
335
        UserGroup $userGroup,
336
        $offset = 0,
337
        $limit = 25,
338
        array $prioritizedLanguages = []
339
    ) {
340
        throw new \Exception('@todo: Implement.');
341
    }
342
343
    /**
344
     * {@inheritdoc}
345
     */
346
    public function isUser(Content $content): bool
347
    {
348
        foreach ($content->getFields() as $field) {
349
            if ($field->fieldTypeIdentifier === 'ezuser') {
350
                return true;
351
            }
352
        }
353
354
        return false;
355
    }
356
357
    /**
358
     * {@inheritdoc}
359
     */
360
    public function isUserGroup(Content $content): bool
361
    {
362
        // TODO: Need a way to identify user groups her. Config is an option, lookup another but not an ideal solution.
363
        return false;
364
    }
365
366
    /**
367
     * Instantiate a user create class.
368
     *
369
     * @param string $login the login of the new user
370
     * @param string $email the email of the new user
371
     * @param string $password the plain password of the new user
372
     * @param string $mainLanguageCode the main language for the underlying content object
373
     * @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
374
     *
375
     * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
376
     */
377
    public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null)
378
    {
379
        throw new \Exception('@todo: Implement.');
380
    }
381
382
    /**
383
     * Instantiate a user group create class.
384
     *
385
     * @param string $mainLanguageCode The main language for the underlying content object
386
     * @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
387
     *
388
     * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct
389
     */
390
    public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null)
391
    {
392
        throw new \Exception('@todo: Implement.');
393
    }
394
395
    /**
396
     * Instantiate a new user update struct.
397
     *
398
     * @return \eZ\Publish\API\Repository\Values\User\UserUpdateStruct
399
     */
400
    public function newUserUpdateStruct()
401
    {
402
        throw new \Exception('@todo: Implement.');
403
    }
404
405
    /**
406
     * Instantiate a new user group update struct.
407
     *
408
     * @return \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct
409
     */
410
    public function newUserGroupUpdateStruct()
411
    {
412
        throw new \Exception('@todo: Implement.');
413
    }
414
415
    /**
416
     * {@inheritdoc}
417
     */
418
    public function validatePassword(string $password, PasswordValidationContext $context = null): array
419
    {
420
        throw new \Exception('@todo: Implement.');
421
    }
422
423
    public function getPasswordInfo(User $user): PasswordInfo
424
    {
425
        throw new \Exception('@todo: Implement.');
426
    }
427
}
428