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


PHP TokenStorage::getToken方法代码示例

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


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

示例1: onCoreController

 /**
  * Update the user "lastActivity" on each request
  *
  * @param FilterControllerEvent $event
  */
 public function onCoreController(FilterControllerEvent $event)
 {
     // Here we are checking that the current request is a "MASTER_REQUEST",
     // and ignore any
     // subrequest in the process (for example when
     // doing a render() in a twig template)
     if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
         return;
     }
     // We are checking a token authentification is available before using
     // the User
     if ($this->tokenStorage->getToken()) {
         $user = $this->tokenStorage->getToken()->getUser();
         // We are using a delay during wich the user will be considered as
         // still active, in order to
         // avoid too much UPDATE in the
         // database
         // $delay = new \DateTime ();
         // $delay
         // ->setTimestamp (strtotime ('2 minutes ago'));
         // We are checking the Admin class in order to be certain we can
         // call "getLastActivity".
         // && $user->getLastActivity() < $delay) {
         if ($user instanceof User) {
             $user->isActiveNow();
             $this->em->persist($user);
             $this->em->flush();
         }
     }
 }
开发者ID:sasedev,项目名称:acf-expert,代码行数:35,代码来源:Activity.php

示例2: isGranted

 protected function isGranted($attribute, $object, $user = null)
 {
     if (!$user) {
         $user = $this->tokenStorage->getToken()->getUser();
     }
     if (!is_object($user)) {
         return false;
     }
     if (in_array('ROLE_ADMINISTRATOR', $user->getRoles())) {
         return true;
     }
     if (!in_array('ROLE_USER', $user->getRoles())) {
         return false;
     }
     if (in_array($attribute, [self::ATTRIBUTE_VIEW, self::ATTRIBUTE_CREATE])) {
         return true;
     }
     /**
      * @var Subcontractor $object
      */
     if ($attribute == self::ATTRIBUTE_EDIT) {
         return $object->getCreatedBy() && $user->getId() == $object->getCreatedBy()->getId() || in_array('ROLE_SUBCONTRACTOR_MANAGER', $user->getRoles());
     }
     return false;
 }
开发者ID:mishki-svami,项目名称:pa-core,代码行数:25,代码来源:SubcontractorVoter.php

示例3: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $user = $this->tokenStorage->getToken()->getUser();
     $builder->add('text')->add('task', EntityType::class, ['class' => 'AppBundle:Task', 'choice_label' => 'name', 'placeholder' => '===== SELECT TASK =====', 'query_builder' => function (EntityRepository $er) use($user) {
         return $er->createQueryBuilder('task')->where('task.owner = :user')->setParameter('user', $user)->orderBy('task.isDefault', 'DESC')->addOrderBy('task.name', 'ASC');
     }])->add('finish', CheckboxType::class, ['mapped' => false, 'required' => false]);
 }
开发者ID:klinki,项目名称:timer,代码行数:11,代码来源:CompleteLogEntryType.php

示例4: collectByUniquenessAction

 /**
  * @Req\Route("/credit/me/profile/balance/collect-operations")
  * @Req\Method({"GET"})
  *
  * @return JsonResponse
  */
 public function collectByUniquenessAction()
 {
     /** @var UsernamePasswordToken $token */
     $token = $this->tokenStorage->getToken();
     $uniqueness = $token->getUsername();
     return new JsonResponse($this->collectOperationsApiWorker->collect($uniqueness));
 }
开发者ID:nabelhm,项目名称:api,代码行数:13,代码来源:CollectOperationsController.php

示例5: onKernelTerminate

 public function onKernelTerminate(PostResponseEvent $event)
 {
     /** @var Request $request */
     $request = $event->getRequest();
     if (!$this->isEnable || !$this->isLoggableRequest($request)) {
         return;
     }
     try {
         /** @var Response $response */
         $response = $event->getResponse();
         $route = $request->get('_route');
         $content = $this->cleanSensitiveContent($route, $request->getContent());
         $token = $this->tokenStorage->getToken();
         $user = !is_null($token) ? $token->getUser() : null;
         $logRequest = new LogRequest();
         $logRequest->setRoute($route)->setPath($request->getPathInfo())->setMethod($request->getMethod())->setQuery(urldecode($request->getQueryString()))->setContent($content)->setStatus($response->getStatusCode())->setIp($request->getClientIp())->setUser(!is_string($user) ? $user : null);
         if ($this->logResponse($response)) {
             $logRequest->setResponse($response->getContent());
         }
         $this->em->persist($logRequest);
         $this->em->flush();
     } catch (\Exception $e) {
         $this->logger->error(sprintf("LogRequest couldn't be persist : %s", $e->getMessage()));
     }
 }
开发者ID:Eraac,项目名称:rest-project,代码行数:25,代码来源:LogRequestListener.php

示例6: getUser

 /**
  * @return User|null
  */
 private function getUser()
 {
     if ($token = $this->tokenStorage->getToken()) {
         return $token->getUser();
     }
     return null;
 }
开发者ID:ekreative,项目名称:server-manager,代码行数:10,代码来源:AuthorEditorListener.php

示例7: isGranted

 /**
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param string|array $attributes
  * @param null $object
  *
  * @return boolean
  */
 public function isGranted(AdminInterface $admin, $attributes, $object = null)
 {
     /** @var Administrator $administrator */
     $administrator = $this->tokenStorage->getToken()->getUser();
     if (!$administrator instanceof Administrator) {
         return false;
     }
     $availableResources = $administrator->getAvailableResources();
     $list = $this->entityManager->getRepository('OctavaAdministratorBundle:Resource')->getList();
     if (!is_array($attributes)) {
         $attributes = [$attributes];
     }
     foreach ($attributes as $attribute) {
         if (in_array($attribute, ["EXPORT", "VIEW"])) {
             $attribute = 'LIST';
         }
         if (!isset($list[get_class($admin)][$attribute])) {
             continue;
         }
         $currentId = $list[get_class($admin)][$attribute];
         if (isset($availableResources[$currentId])) {
             return true;
         }
     }
     return false;
 }
开发者ID:octava,项目名称:cms,代码行数:33,代码来源:AdministratorHandler.php

示例8: pickAction

 /**
  * @Req\Route("/info-sms/me/pick-profile")
  * @Req\Method({"GET"})
  *
  * @return JsonResponse
  */
 public function pickAction()
 {
     /** @var UsernamePasswordToken $token */
     $token = $this->tokenStorage->getToken();
     $uniqueness = $token->getUsername();
     return new JsonResponse($this->pickProfileApiWorker->pick($uniqueness));
 }
开发者ID:nabelhm,项目名称:api,代码行数:13,代码来源:PickProfileController.php

示例9: onAuthenticationSuccess

 /**
  * @param Request $request
  * @param TokenInterface $token
  * @return RedirectResponse
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     // Get current user
     $currentUser = $this->security->getToken()->getUser();
     $currentUsername = $currentUser->getUsername();
     if ($currentUsername != 'sys' && $currentUsername != 'admin') {
         // Get Ldap User
         $ldapUser = $this->ldap->findUserByUsername($currentUser->getUsername());
         // Get DB Stored User
         $dbUser = $this->em->getRepository('SpiritDevDBoxUserBundle:User')->find($currentUser->getId());
         // Merge DB User with Ldap User
         $dbUser->setDn($ldapUser->getDn());
         $dbUser->setLastName($ldapUser->getLastName());
         $dbUser->setFirstName($ldapUser->getFirstName());
         $dbUser->setEmail($ldapUser->getEmail());
         $dbUser->setEmailCanonical($ldapUser->getEmail());
         $dbUser->setUsername($ldapUser->getUsername());
         $dbUser->setUsernameCanonical($ldapUser->getUsername());
         $dbUser->setLanguage($ldapUser->getLanguage());
         // Save in db
         $this->em->flush();
         // Update session user
         $this->security->getToken()->setUser($dbUser);
     }
     // Redirect
     $referer_url = $this->router->generate('spirit_dev_dbox_portal_bundle_introduction');
     return new RedirectResponse($referer_url);
 }
开发者ID:spirit-dev,项目名称:dbox-user,代码行数:33,代码来源:LoginSuccessHandler.php

示例10: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $routes = $this->router->getRouteCollection();
     $route = $routes->get($request->attributes->get('_route'));
     if (!$route->getOption('requires_license')) {
         return;
     }
     if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
         // Checking for whitelisted users
         try {
             $user = $this->tokenStorage->getToken()->getUser();
             $today = date('Y-m-d');
             if ($user instanceof UserInterface) {
                 $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                 foreach ($whitelist as $allowed) {
                     if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
                         return;
                     }
                 }
             }
         } catch (\Exception $e) {
             // Do nothing
         }
         $url = $this->router->generate('atlassian_connect_unlicensed');
         $response = new RedirectResponse($url);
         $event->setResponse($response);
     }
 }
开发者ID:sainthardaway,项目名称:atlassian-connect-bundle,代码行数:32,代码来源:LicenseListener.php

示例11: contactAction

 /**
  * @Route("/contact", name="contact_route")
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function contactAction(Request $request)
 {
     /** @var AnonymousToken $token */
     $token = $this->tokenStorage->getToken();
     /** @var User $user */
     $user = $token->getUser();
     $contact = new Contact();
     if ($user !== 'anon.') {
         /** @var User $user */
         $contact->setEmail($user->getEmail());
         $contact->setUser($user);
     }
     $emailGetParam = $request->query->get('email');
     if (!empty($emailGetParam)) {
         $contact->setEmail($emailGetParam);
     }
     $form = $this->formFactory->createBuilder(FormType::class, $contact)->add('email', TextType::class, ['attr' => ['placeholder' => 'votre@adresse.email']])->add('message', TextareaType::class, ['attr' => ['maxlength' => 1000, 'rows' => 10]])->add('submit', SubmitType::class, ['label' => 'Envoyer'])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->contactService->record($contact);
         $this->session->getFlashBag()->add(static::FLASH_BAG_EMAIL, $contact->getEmail());
         return new RedirectResponse($this->router->generate('confirmation_contact_route'));
     } else {
         return new Response($this->templating->render('base.html.twig', [TwigNodeTemplateTreeSection::TEMPLATE_TREE_BRANCH => 'contact', 'form' => $form->createView()]), $form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK);
     }
 }
开发者ID:apflieger,项目名称:zigotoo,代码行数:31,代码来源:ContactController.php

示例12: save

 public function save(ContentInterface $content)
 {
     if (!$content->getId()) {
         $content->setAuthor($this->tokenStorage->getToken()->getUser());
     }
     return parent::save($content);
 }
开发者ID:Opifer,项目名称:Cms,代码行数:7,代码来源:ContentManager.php

示例13: configureOptions

 /**
  * @param OptionsResolver $resolver
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $user = $this->tokenStorage->getToken()->getUser();
     $resolver->setDefaults(array('data_class' => Task::class, 'empty_data' => function (FormInterface $form) use($user) {
         return new Task($form->getData()['name'], $user);
     }));
 }
开发者ID:klinki,项目名称:timer,代码行数:10,代码来源:TaskType.php

示例14: getUser

 /**
  * Returns the PartKeeprUser based on the user token within the Symfony2 environment.
  *
  * @return User The proxy user
  */
 public function getUser()
 {
     $tokenProvider = $this->tokenStorage->getToken()->getAttribute("provider");
     $provider = $this->getProvider($tokenProvider);
     $username = $this->tokenStorage->getToken()->getUsername();
     return $this->getProxyUser($username, $provider, true);
 }
开发者ID:fulcrum3d,项目名称:PartKeepr,代码行数:12,代码来源:UserService.php

示例15: create

 /**
  * @param Request $request
  *
  * @return JsonResponse
  *
  * @throws \Assert\AssertionFailedException
  * @throws InvalidMobileApiException
  * @throws BlankAliasApiException
  * @throws NoTopicsApiException
  * @throws InsufficientBalanceApiException
  * @throws ExistentMobileApiException
  */
 protected function create(Request $request)
 {
     /** @var UsernamePasswordToken $token */
     $token = $this->tokenStorage->getToken();
     $uniqueness = $token->getUsername();
     $data = $request->request->all();
     foreach (array('mobile', 'alias', 'topics') as $key) {
         Assertion::keyExists($data, $key);
     }
     try {
         $this->createSubscriptionApiWorker->create($data['mobile'], $uniqueness, $data['alias'], $data['topics'], $data['resellPackage']);
     } catch (InvalidMobileApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.INVALID_MOBILE'), 400);
     } catch (BlankAliasApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.BLANK_ALIAS'), 400);
     } catch (ExistentMobileApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.EXISTENT_MOBILE'), 400);
     } catch (NoTopicsApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_TOPICS'), 400);
     } catch (NoResellPackageApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_RESELL_PACKAGE'), 400);
     } catch (TrialNotAcceptedApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.TRIAL_NOT_ACCEPTED'), 400);
     } catch (InsufficientBalanceApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.PROFILE.INSUFFICIENT_BALANCE'), 400);
     }
     return new JsonResponse();
 }
开发者ID:nabelhm,项目名称:api,代码行数:40,代码来源:AbstractCreateSubscriptionController.php


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