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


PHP Presenter::checkRequirements方法代码示例

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


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

示例1: checkRequirements

 /**
  * {@inheritdoc}
  *
  * @throws ForbiddenRequestException
  */
 public function checkRequirements($element)
 {
     parent::checkRequirements($element);
     if ($element instanceof ClassType) {
         return;
     }
     //not checking class access, only method access
     $user = $this->getUser();
     // Allowing for both method level and class level annotations
     $class = $element instanceof Method ? $element->getDeclaringClass() : $element;
     $secured = $element->getAnnotation('Secured') || $class->getAnnotation('Secured');
     if ($secured) {
         if (!$user->isLoggedIn()) {
             throw new ForbiddenRequestException("User has to be logged in to access secured presenter.");
         } else {
             //check existence of resource
             if (!($element->hasAnnotation('Resource') || $class->hasAnnotation('Resource'))) {
                 throw new InvalidStateException('Secured method is missing a resource.');
             }
             $resource = $element->hasAnnotation('Resource') ? $element->getAnnotation('Resource') : $class->getAnnotation('Resource');
             $privileges = array_merge((array) $class->getAnnotation('Privilege'), (array) $element->getAnnotation('Privilege'));
             foreach ($privileges as $privilege) {
                 if ($user->isAllowed($resource, $privilege)) {
                     return;
                 }
             }
             throw new ForbiddenRequestException("User is not allowed to access resource '{$resource}'");
         }
     }
 }
开发者ID:patrickkusebauch,项目名称:nette-security-annotation,代码行数:35,代码来源:SecurePresenterAbstract.php

示例2: checkRequirements

 /**
  * Check presenter requirements
  * @param $element
  * @throws ForbiddenRequestException
  */
 public function checkRequirements($element)
 {
     parent::checkRequirements($element);
     $accessToken = $this->input->getAuthorization();
     if (!$accessToken) {
         throw new ForbiddenRequestException('Access token not provided');
     }
     $this->checkAccessToken($accessToken);
 }
开发者ID:drahak,项目名称:oauth2,代码行数:14,代码来源:ResourcePresenter.php

示例3: checkRequirements

 public function checkRequirements($element)
 {
     if ($this->securityToken !== null && $element instanceof Application\UI\PresenterComponentReflection) {
         if ($this->getParameter('token') != $this->securityToken->getSecurityToken()) {
             throw new Application\ForbiddenRequestException('Security token does not match!');
         }
     }
     parent::checkRequirements($element);
 }
开发者ID:foowie,项目名称:cron,代码行数:9,代码来源:CronPresenter.php

示例4: checkRequirements

 /**
  * @param \Nette\Reflection\Method $element
  * @throws \Nette\Application\ForbiddenRequestException
  */
 public function checkRequirements($element)
 {
     parent::checkRequirements($element);
     if ($element instanceof \Nette\Reflection\Method) {
         $method = $element->getName();
         if (Strings::match($method, '/^createComponent|handle/') !== NULL && $element->hasAnnotation('action')) {
             $action = (array) $element->getAnnotation('action');
             if (!in_array($this->getAction(), $action, TRUE)) {
                 throw new \Nette\Application\ForbiddenRequestException();
             }
         }
     }
 }
开发者ID:brosland,项目名称:framework,代码行数:17,代码来源:Presenter.php

示例5: checkRequirements

 /**
  * Check permissions for action
  * @param $element
  */
 public function checkRequirements($element)
 {
     parent::checkRequirements($element);
     $permission = (array) $element->getAnnotation('permission');
     if ($permission) {
         if (count($permission) === 1) {
             $resource = $permission[0];
             $privilege = Permission::ALL;
         } else {
             list($resource, $privilege) = array_values($permission);
         }
         if (!$this->getUser()->isAllowed($resource, $privilege)) {
             $this->redirectToHomepage($this->translate("admin.permission.error"), 'error');
         }
     }
 }
开发者ID:pecinaon,项目名称:sandbox,代码行数:20,代码来源:Presenter.php

示例6: checkRequirements

 /**
  * Checks authorization.
  *
  * @param string $element
  * @return void
  * @throws Application\ForbiddenRequestException
  */
 public function checkRequirements($element)
 {
     try {
         parent::checkRequirements($element);
         if (!$this->requirementsChecker->isAllowed($element)) {
             throw new Application\ForbiddenRequestException();
         }
     } catch (Application\ForbiddenRequestException $e) {
         $this->flashMessage('Pro vstup do požadované sekce musíte být přihlášen/a s příslušným oprávněním.');
         if (!$this->user->isLoggedIn()) {
             $this->redirect('Sign:in', ['backSignInUrl' => $this->getHttpRequest()->url->path]);
         } elseif (!$this->isLinkCurrent('Homepage:')) {
             $this->redirect('Homepage:');
         } else {
             $this->redirect('Sign:in');
         }
     }
 }
开发者ID:cothema,项目名称:cmsbe,代码行数:25,代码来源:BasePresenter.php

示例7: checkRequirements

 /**
  * Check permissions by annotations
  * {@inheritdoc}
  */
 public function checkRequirements($element)
 {
     parent::checkRequirements($element);
     if ($element instanceof \Nette\Reflection\ClassType) {
         return;
     }
     //not checking class access, only method access
     $user = $this->user;
     // Allowing for both method level and class level annotations
     $class = $element instanceof \Nette\Reflection\Method ? $element->getDeclaringClass() : $element;
     $secured = $element->getAnnotation('Secured') || $class->getAnnotation('Secured');
     if ($secured) {
         if (!$user->isLoggedIn()) {
             if ($user->getLogoutReason() === IUserStorage::INACTIVITY) {
                 $this->flashMessage("Byl jsi odhlášen, protože jsi nebyl po dlouhou dobu aktivní.");
             } else {
                 $this->flashMessage("Pro vstup do této části webu se musíš přihlásit.");
             }
             $this->redirect(":Front:Default:Sign:in", array("backlink" => $this->storeRequest()));
         } else {
             //check existence of resource
             if (!($element->hasAnnotation('Resource') || $class->hasAnnotation('Resource'))) {
                 throw new \Nette\InvalidStateException('Secured method is missing a resource.');
             }
             $resource = $element->hasAnnotation('Resource') ? $element->getAnnotation('Resource') : $class->getAnnotation('Resource');
             $privileges = array_merge((array) $class->getAnnotation('Privilege'), (array) $element->getAnnotation('Privilege'));
             $allowed = FALSE;
             foreach ($privileges as $privilege) {
                 if ($user->isAllowed($resource, $privilege)) {
                     $allowed = TRUE;
                 }
             }
             if (!$allowed) {
                 throw new \Nette\Application\ForbiddenRequestException("Pro vstup do této části webu nemáte dostatečná oprávnění", 403);
             }
         }
     }
 }
开发者ID:patrickkusebauch,项目名称:27skauti,代码行数:42,代码来源:BasePresenter.php

示例8: checkRequirements

 /**
  * Check security and other presenter requirements
  * @param $element
  */
 public function checkRequirements($element)
 {
     try {
         parent::checkRequirements($element);
     } catch (Application\ForbiddenRequestException $e) {
         $this->sendErrorResource($e);
     }
     // Try to authenticate client
     try {
         $this->authentication->authenticate($this->getInput());
     } catch (SecurityException $e) {
         $this->sendErrorResource($e);
     }
 }
开发者ID:lucien144,项目名称:Restful,代码行数:18,代码来源:ResourcePresenter.php


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