/** * Returns true if user with given login name exists * * @param string $login * @return bool */ private function isExistingUser($login) { try { $this->userService->loadUserByLogin($login); return true; } catch (NotFoundException $exception) { return false; } }
/** * Loads users. * * @return \eZ\Publish\Core\REST\Server\Values\UserList|\eZ\Publish\Core\REST\Server\Values\UserRefList */ public function loadUsers(Request $request) { $restUsers = array(); try { if ($request->query->has('roleId')) { $restUsers = $this->loadUsersAssignedToRole($this->requestParser->parseHref($request->query->get('roleId'), 'roleId')); } elseif ($request->query->has('remoteId')) { $restUsers = array($this->buildRestUserObject($this->userService->loadUser($this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'))->id))); } elseif ($request->query->has('login')) { $restUsers = array($this->buildRestUserObject($this->userService->loadUserByLogin($request->query->get('login')))); } elseif ($request->query->has('email')) { foreach ($this->userService->loadUsersByEmail($request->query->get('email')) as $user) { $restUsers[] = $this->buildRestUserObject($user); } } } catch (ApiExceptions\UnauthorizedException $e) { $restUsers = []; } if (empty($restUsers)) { throw new NotFoundException('No users were found with the given filter'); } if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') { return new Values\UserList($restUsers, $request->getPathInfo()); } return new Values\UserRefList($restUsers, $request->getPathInfo()); }
/** * @Then User with name :username has the following fields: * @Then User with name :username exists with the following fields: * * Checks that user ':username' exists with the values provided in the field/value table. example: * | Name | value | * | email | testuser@ez.no | * | password | testuser | * | first_name | Test | * | last_name | User | */ public function assertUserWithNameExistsWithFields($username, TableNode $table) { Assertion::assertTrue($this->checkUserExistenceByUsername($username), "Couldn't find User with name '{$username}'."); $user = $this->userService->loadUserByLogin($username); $fieldsTable = $table->getTable(); array_shift($fieldsTable); $updateFields = array(); foreach ($fieldsTable as $fieldRow) { $fieldName = $fieldRow[0]; $expectedValue = $fieldRow[1]; switch ($fieldName) { case 'email': $fieldValue = $user->email; break; case 'password': $fieldValue = $user->passwordHash; $expectedValue = $this->createPasswordHash($username, $expectedValue, $user->hashAlgorithm); break; default: $fieldValue = $user->getFieldValue($fieldName); } Assertion::assertEquals($expectedValue, $fieldValue, "Field '{$fieldName}' did not contain expected value '{$expectedValue}'."); } }
/** * Loads a user for the given login * * @param string $login * * @return \eZ\Publish\API\Repository\Values\User\User * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found */ public function loadUserByLogin($login) { return $this->service->loadUserByLogin($login); }
/** * Trigger * * @param InteractiveLoginEvent $event */ public function onInteractiveLogin(InteractiveLoginEvent $event) { // We just load a generic user and assign it back to the event. // You may want to create users here, or even load predefined users depending on your own rules. $event->setApiUser($this->userService->loadUserByLogin('member')); }
/** * Sets the current ez user to the user with the given user name. * * @param string $username */ private function setMigrationUser($username) { $this->repository->setCurrentUser($this->userService->loadUserByLogin($username)); }