当前位置: 首页>>代码示例>>PHP>>正文


PHP Repository::setCurrentUser方法代码示例

本文整理汇总了PHP中eZ\Publish\API\Repository\Repository::setCurrentUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::setCurrentUser方法的具体用法?PHP Repository::setCurrentUser怎么用?PHP Repository::setCurrentUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZ\Publish\API\Repository\Repository的用法示例。


在下文中一共展示了Repository::setCurrentUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
     }
 }
开发者ID:emodric,项目名称:LegacyBridge,代码行数:31,代码来源:RequestListener.php

示例2: 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);
 }
开发者ID:kuborgh,项目名称:ezsc15,代码行数:10,代码来源:ContentCreateService.php

示例3: 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)));
     }
     $this->repository->setCurrentUser($user->getAPIUser());
     return $user;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:22,代码来源:Provider.php

示例4: handleAction

 public function handleAction(Request $request)
 {
     $user = $this->userService->loadUserByCredentials($request->username, $request->password);
     $this->repository->setCurrentUser($user);
     $contentCreateStruct = $this->contentProvider->newContentCreateStructFromRequest($request);
     $locationCreateStruct = $this->contentProvider->newLocationCreateStructFromRequest($request);
     $content = $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
     $this->contentService->publishVersion($content->versionInfo);
 }
开发者ID:bdunogier,项目名称:eziftttbundle,代码行数:9,代码来源:Handler.php

示例5: 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);
     }
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:28,代码来源:Provider.php

示例6: 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);
     }
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:21,代码来源:RequestListener.php

示例7: 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);
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:35,代码来源:SecurityListener.php

示例8: 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));
 }
开发者ID:rihards,项目名称:NovaeZSEOBundle,代码行数:12,代码来源:AddNovaSEOMetasFieldTypeCommand.php

示例9: 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);
 }
开发者ID:Novactive,项目名称:NovaeZFOSUserBundle,代码行数:24,代码来源:ImplicitLoginListener.php

示例10: checkAuthentication

 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     if (!$user instanceof EzUserInterface) {
         return parent::checkAuthentication($user, $token);
     }
     // $currentUser can either be an instance of UserInterface or just the username (e.g. during form login).
     /** @var EzUserInterface|string $currentUser */
     $currentUser = $token->getUser();
     if ($currentUser instanceof UserInterface) {
         if ($currentUser->getAPIUser()->passwordHash !== $user->getAPIUser()->passwordHash) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
         $apiUser = $currentUser->getAPIUser();
     } else {
         try {
             $apiUser = $this->repository->getUserService()->loadUserByCredentials($token->getUsername(), $token->getCredentials());
         } catch (NotFoundException $e) {
             throw new BadCredentialsException('Invalid credentials', 0, $e);
         }
     }
     // Finally inject current user in the Repository
     $this->repository->setCurrentUser($apiUser);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:23,代码来源:RepositoryAuthenticationProvider.php

示例11: login

 public function login($username, $password)
 {
     $this->repository->setCurrentUser($this->repository->getUserService()->loadUserByCredentials($username, $password));
 }
开发者ID:bdunogier,项目名称:ezwordpressapibundle,代码行数:4,代码来源:EzPublishRepository.php

示例12: login

 private function login($username, $password)
 {
     $this->repository->setCurrentUser($this->userService->loadUserByCredentials($username, $password));
 }
开发者ID:bdunogier,项目名称:wordpressapibundle,代码行数:4,代码来源:DefaultController.php

示例13: setCurrentUser

 /**
  * Sets the current user to the given $user.
  *
  * @param \eZ\Publish\API\Repository\Values\User\User $user
  *
  * @return void
  */
 public function setCurrentUser(User $user)
 {
     return $this->repository->setCurrentUser($user);
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:11,代码来源:Repository.php

示例14: setMigrationUser

 /**
  * Sets the current ez user to the user with the given user name.
  *
  * @param string $username
  */
 private function setMigrationUser($username)
 {
     $this->repository->setCurrentUser($this->repository->getUserService()->loadUserByLogin($username));
 }
开发者ID:kreait,项目名称:ezpublish-migrations-bundle,代码行数:9,代码来源:EzPublishMigration.php

示例15: loginAdmin

 /**
  * @BeforeScenario
  */
 public function loginAdmin($event)
 {
     $this->repository->setCurrentUser(new UserReference($this->adminUserId));
 }
开发者ID:ezsystems,项目名称:behatbundle,代码行数:7,代码来源:RepositoryContext.php


注:本文中的eZ\Publish\API\Repository\Repository::setCurrentUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。