本文整理汇总了PHP中eZ\Publish\API\Repository\Repository::getUserService方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::getUserService方法的具体用法?PHP Repository::getUserService怎么用?PHP Repository::getUserService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\Repository
的用法示例。
在下文中一共展示了Repository::getUserService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: auth
/**
* Set admin as current user
*/
public function auth()
{
$userService = $this->apiRepository->getUserService();
$user = $userService->loadUserByLogin('admin');
// login user for API
$this->apiRepository->setCurrentUser($user);
}
示例2: onKernelRequest
/**
* If user is logged-in in legacy_mode (e.g. legacy admin interface),
* will inject currently logged-in user in the repository.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */
$request = $event->getRequest();
$session = $request->getSession();
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST || !$this->configResolver->getParameter('legacy_mode') || !($session->isStarted() && $session->has('eZUserLoggedInID'))) {
return;
}
try {
$apiUser = $this->repository->getUserService()->loadUser($session->get('eZUserLoggedInID'));
$this->repository->setCurrentUser($apiUser);
$token = $this->tokenStorage->getToken();
if ($token instanceof TokenInterface) {
$token->setUser(new User($apiUser));
// Don't embed if we already have a LegacyToken, to avoid nested session storage.
if (!$token instanceof LegacyToken) {
$this->tokenStorage->setToken(new LegacyToken($token));
}
}
} catch (NotFoundException $e) {
// Invalid user ID, the user may have been removed => invalidate the token and the session.
$this->tokenStorage->setToken(null);
$session->invalidate();
}
}
示例3: pre
/**
* Initializes eZ Publish related service shortcuts.
*
* @param Schema $schema
*/
protected function pre(Schema $schema)
{
$this->repository = $this->container->get('ezpublish.api.repository');
$this->userService = $this->repository->getUserService();
$this->defaultMigrationUser = $this->container->getParameter('ezpublish_migrations.ez_user');
$this->currentMigrationUser = $this->defaultMigrationUser;
$this->setDefaultMigrationUser();
}
示例4: __construct
/**
* @param \eZ\Publish\API\Repository\Repository $repository
* @param ConfigResolverInterface|\Psr\Log\LoggerInterface $resolver
*/
public function __construct(Repository $repository, ConfigResolverInterface $resolver)
{
$this->repository = $repository;
$this->searchService = $this->repository->getSearchService();
$this->locationService = $this->repository->getLocationService();
$this->contentService = $this->repository->getContentService();
$this->languageService = $this->repository->getContentLanguageService();
$this->userService = $this->repository->getUserService();
$this->contentTypeService = $this->repository->getContentTypeService();
$this->configResolver = $resolver;
}
示例5: createNewUser
/**
* @param $login
* @param $email
* @param $firstName
* @param $lastName
* @return User
*/
public function createNewUser($login, $email, $firstName, $lastName)
{
$userService = $this->repository->getUserService();
$userCreateStruct = $userService->newUserCreateStruct($login, $email, md5($email . $login . time() . rand(1, 10000)), 'eng-GB', $this->repository->getContentTypeService()->loadContentTypeByIdentifier('user'));
$userCreateStruct->setField('first_name', $firstName);
$userCreateStruct->setField('last_name', $lastName);
$user = $this->repository->sudo(function () use($userService, $userCreateStruct) {
$userGroup = $userService->loadUserGroup('11');
// guest accounts
return $userService->createUser($userCreateStruct, array($userGroup));
});
return $user;
}
示例6: refreshUser
/**
* Refreshes the user for the account interface.
*
* It is up to the implementation to decide if the user data should be
* totally reloaded (e.g. from the database), or if the UserInterface
* object can just be merged into some internal array of users / identity
* map.
*
* @param \Symfony\Component\Security\Core\User\UserInterface $user
*
* @throws \Symfony\Component\Security\Core\Exception\UnsupportedUserException
*
* @return \Symfony\Component\Security\Core\User\UserInterface
*/
public function refreshUser(CoreUserInterface $user)
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}
try {
$refreshedAPIUser = $this->repository->getUserService()->loadUser($user->getAPIUser()->id);
$user->setAPIUser($refreshedAPIUser);
$this->repository->setCurrentUser($refreshedAPIUser);
return $user;
} catch (NotFoundException $e) {
throw new UsernameNotFoundException($e->getMessage(), 0, $e);
}
}
示例7: loadUserByUsername
/**
* Loads the user for the given user ID.
* $user can be either the user ID or an instance of \eZ\Publish\Core\MVC\Symfony\Security\User
* (anonymous user we try to check access via SecurityContext::isGranted())
*
* @param string|\eZ\Publish\Core\MVC\Symfony\Security\User $user Either the user ID to load an instance of User object. A value of -1 represents an anonymous user.
*
* @return \eZ\Publish\Core\MVC\Symfony\Security\UserInterface
*
* @throws \Symfony\Component\Security\Core\Exception\UsernameNotFoundException if the user is not found
*/
public function loadUserByUsername($user)
{
try {
// SecurityContext always tries to authenticate anonymous users when checking granted access.
// In that case $user is an instance of \eZ\Publish\Core\MVC\Symfony\Security\User.
// We don't need to reload the user here.
if ($user instanceof UserInterface) {
return $user;
}
return new User($this->repository->getUserService()->loadUserByLogin($user), array('ROLE_USER'));
} catch (NotFoundException $e) {
throw new UsernameNotFoundException($e->getMessage(), 0, $e);
}
}
示例8: onKernelRequest
/**
* If user is logged-in in legacy_mode (e.g. legacy admin interface),
* will inject currently logged-in user in the repository.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */
$request = $event->getRequest();
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST || !$this->configResolver->getParameter('legacy_mode') || !$request->getSession()->has('eZUserLoggedInID')) {
return;
}
$apiUser = $this->repository->getUserService()->loadUser($request->getSession()->get('eZUserLoggedInID'));
$this->repository->setCurrentUser($apiUser);
$token = $this->securityContext->getToken();
if ($token instanceof TokenInterface) {
$token->setUser(new User($apiUser));
$token->setAuthenticated(true);
}
}
示例9: onInteractiveLogin
/**
* Tries to retrieve a valid eZ user if authenticated user doesn't come from the repository (foreign user provider).
* Will dispatch an event allowing listeners to return a valid eZ user for current authenticated user.
* Will by default let the repository load the anonymous user.
*
* @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event
*/
public function onInteractiveLogin(BaseInteractiveLoginEvent $event)
{
$token = $event->getAuthenticationToken();
$originalUser = $token->getUser();
if ($originalUser instanceof eZUser || !$originalUser instanceof UserInterface) {
return;
}
/*
* 1. Send the event.
* 2. If no eZ user is returned, load Anonymous user.
* 3. Inject eZ user in repository.
* 4. Create the UserWrapped user object (implementing eZ UserInterface) with loaded eZ user.
* 5. Create new token with UserWrapped user
* 6. Inject the new token in security context
*/
$subLoginEvent = new InteractiveLoginEvent($event->getRequest(), $token);
$this->eventDispatcher->dispatch(MVCEvents::INTERACTIVE_LOGIN, $subLoginEvent);
if ($subLoginEvent->hasAPIUser()) {
$apiUser = $subLoginEvent->getAPIUser();
} else {
$apiUser = $this->repository->getUserService()->loadUser($this->configResolver->getParameter("anonymous_user_id"));
}
$this->repository->setCurrentUser($apiUser);
$providerKey = method_exists($token, 'getProviderKey') ? $token->getProviderKey() : __CLASS__;
$interactiveToken = new InteractiveLoginToken($this->getUser($originalUser, $apiUser), get_class($token), $token->getCredentials(), $providerKey, $token->getRoles());
$interactiveToken->setAttributes($token->getAttributes());
$this->securityContext->setToken($interactiveToken);
}
示例10: mapContentCreateToUserCreate
private function mapContentCreateToUserCreate(RestContentCreateStruct $restContentCreateStruct)
{
$contentCreateStruct = $restContentCreateStruct->contentCreateStruct;
$userCreateStruct = new UserCreateStruct();
$fields = array();
foreach ($contentCreateStruct->fields as $field) {
// @todo fix hardcode user_account
if ($field->value instanceof UserFieldValue) {
$userCreateStruct->login = $field->value->login;
$userCreateStruct->email = $field->value->email;
$userCreateStruct->password = $field->value->passwordHash;
$field->value->passwordHash = null;
$foundUserField = true;
}
$userCreateStruct->fields[] = $field;
}
if (!isset($foundUserField)) {
return false;
}
$properties = ['contentType', 'sectionId', 'ownerId', 'alwaysAvailable', 'remoteId', 'mainLanguageCode', 'modificationDate'];
foreach ($properties as $property) {
if (isset($contentCreateStruct->{$property})) {
$userCreateStruct->{$property} = $contentCreateStruct->{$property};
}
}
$userGroup = $this->repository->getUserService()->loadUserGroup($restContentCreateStruct->locationCreateStruct->parentLocationId);
return [$userCreateStruct, $userGroup];
}
示例11: getUserService
/**
* Get User Service
*
* Get service object to perform operations on Users and UserGroup
*
* @return \eZ\Publish\API\Repository\UserService
*/
public function getUserService()
{
if ($this->userService !== null) {
return $this->userService;
}
$this->userService = new UserService($this->repository->getUserService(), $this->signalDispatcher);
return $this->userService;
}
示例12: initialize
/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$input;
// phpmd trick
$output;
// phpmd trick
$this->eZPublishRepository = $this->getContainer()->get("ezpublish.api.repository");
$this->eZPublishRepository->setCurrentUser($this->eZPublishRepository->getUserService()->loadUser(14));
}
示例13: buildDomainUserGroupRoleAssignmentObject
/**
* Builds the API UserGroupRoleAssignment object from provided SPI RoleAssignment object
*
* @param \eZ\Publish\SPI\Persistence\User\RoleAssignment $spiRoleAssignment
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
* @param \eZ\Publish\API\Repository\Values\User\Role $role
*
* @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment
*/
public function buildDomainUserGroupRoleAssignmentObject(SPIRoleAssignment $spiRoleAssignment, UserGroup $userGroup = null, APIRole $role = null)
{
$limitation = null;
if (!empty($spiRoleAssignment->limitationIdentifier)) {
$limitation = $this->getLimitationType($spiRoleAssignment->limitationIdentifier)->buildValue($spiRoleAssignment->values);
}
$userGroup = $userGroup ?: $this->repository->getUserService()->loadUserGroup($spiRoleAssignment->contentId);
$role = $role ?: $this->loadRole($spiRoleAssignment->roleId);
return new UserGroupRoleAssignment(array('limitation' => $limitation, 'role' => $role, 'userGroup' => $userGroup));
}
示例14: __construct
public function __construct(Repository $repository, CategoryServiceInterface $categoryService, PostServiceInterface $postService)
{
$this->repository = $repository;
$this->categoryService = $categoryService;
$this->postService = $postService;
$this->searchService = $repository->getSearchService();
$this->contentService = $repository->getContentService();
$this->locationService = $repository->getLocationService();
$this->contentTypeService = $repository->getContentTypeService();
$this->userService = $repository->getUserService();
}
示例15: onImplicitLogin
/**
* @param UserEvent $event
*/
public function onImplicitLogin(UserEvent $event)
{
$originalUser = $event->getUser();
if ($originalUser instanceof eZUser || !$originalUser instanceof UserInterface) {
return;
}
// Already Authenticated Token ( we are in ImplicitLogin of FOS)
$token = $this->tokenStorage->getToken();
$subLoginEvent = new InteractiveLoginEvent($event->getRequest(), $token);
$this->eventDispatcher->dispatch(MVCEvents::INTERACTIVE_LOGIN, $subLoginEvent);
if ($subLoginEvent->hasAPIUser()) {
$apiUser = $subLoginEvent->getAPIUser();
} else {
$apiUser = $this->repository->getUserService()->loadUser($this->configResolver->getParameter('anonymous_user_id'));
}
$this->repository->setCurrentUser($apiUser);
$providerKey = method_exists($token, 'getProviderKey') ? $token->getProviderKey() : __CLASS__;
$interactiveToken = new InteractiveLoginToken(new UserWrapped($originalUser, $apiUser), get_class($token), $token->getCredentials(), $providerKey, $token->getRoles());
$interactiveToken->setAttributes($token->getAttributes());
$this->tokenStorage->setToken($interactiveToken);
}