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


PHP User::getRoles方法代码示例

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


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

示例1: extractRoles

 private function extractRoles()
 {
     $userRoles = $this->user->getRoles();
     if ($this->roleHierarchy) {
         return $this->roleHierarchy->getReachableRoles($userRoles);
     }
     return $userRoles;
 }
开发者ID:zycon42,项目名称:security,代码行数:8,代码来源:ExpressionEvaluator.php

示例2: check

 public function check($resource, $privilege)
 {
     if ($this->user->isInRole(static::ROOT_ROLE)) {
         return true;
     }
     if (!array_reduce($this->user->getRoles(), function ($prev, $role) use($resource, $privilege) {
         return $this->acl->hasRole($role) && $this->acl->hasResource($resource) && $this->acl->isAllowed($role, $resource, $privilege) || $prev;
     }, false)) {
         throw new \AclException("Unauthorized access to resource '{$resource}' privilege '{$privilege}' :(", 403);
     }
 }
开发者ID:v108b,项目名称:nette-acl,代码行数:11,代码来源:AclHelper.php

示例3: process

 /**
  * @Around("methodAnnotatedWith(Klimesf\Secured\Secured)")
  */
 public function process(AroundMethod $m)
 {
     $secured = $this->getAnnotation($m);
     foreach ($secured->roles as $role) {
         if (!$this->user->isLoggedIn()) {
             break;
         }
         if (in_array($role, $this->user->getRoles())) {
             return $m->proceed();
         }
     }
     $parentClass = $m->getTargetObjectReflection()->parentClass->name;
     $methodName = $m->getTargetReflection()->name;
     throw new AuthenticationException("User is not allowed to call " . $parentClass . '::' . $methodName . "().");
 }
开发者ID:klimesf,项目名称:secured,代码行数:18,代码来源:SecuredAspect.php

示例4: checkMethod

 /**
  * @param \Nette\Reflection\Method $element
  */
 protected function checkMethod(Method $element)
 {
     $class = $element->class;
     $name = $element->name;
     $schema = $this->reader->getSchema($class);
     $exception = null;
     // users
     if (isset($schema[$name]['users']) && count($schema[$name]['users']) > 0) {
         $users = $schema[$name]['users'];
         if (!in_array($this->user->getId(), $users)) {
             $exception = sprintf('Access denied for your username: \'%s\'. Require: \'%s\'', $this->user->getId(), implode(', ', $users));
         } else {
             return;
         }
     } elseif (isset($schema[$name]['roles']) && count($schema[$name]['roles']) > 0) {
         $userRoles = $this->user->getRoles();
         $roles = $schema[$name]['roles'];
         if (count(array_intersect($userRoles, $roles)) == 0) {
             $exception = "Access denied for your roles: '" . implode(', ', $userRoles) . "'. Require one of: '" . implode(', ', $roles) . "'";
         } else {
             return;
         }
     } elseif (isset($schema[$name]['resource']) && $schema[$name]['resource']) {
         if (!$this->user->isAllowed($schema[$name]['resource'], $schema[$name]['privilege'])) {
             $exception = sprintf('Access denied for resource: \'%s\' and privilege: \'%s\'', $schema[$name]['resource'], $schema[$name]['privilege']);
         } else {
             return;
         }
     }
     if ($exception) {
         throw new ForbiddenRequestException($exception);
     }
 }
开发者ID:venne,项目名称:venne,代码行数:36,代码来源:ControlVerifier.php

示例5: loadFromSession

 public static function loadFromSession(\Nette\Security\User $user)
 {
     $instance = new User();
     $instance->setId($user->getIdentity()->id);
     $instance->setRole($user->getRoles()[0]);
     $instance->setEmail($user->getIdentity()->email);
     $instance->setFirstName($user->getIdentity()->firstName);
     $instance->setLastName($user->getIdentity()->lastName);
     return $instance;
 }
开发者ID:jaromir92,项目名称:Sportwin,代码行数:10,代码来源:UserService.php

示例6: isAtLeastInRole

 /**
  * @return bool
  */
 public function isAtLeastInRole($role, Nette\Security\User $user)
 {
     $result = TRUE;
     foreach ($user->getRoles() as $userRole) {
         if ($userRole === $role) {
             return TRUE;
         }
         $result &= $this->acl->roleInheritsFrom($userRole, $role);
     }
     return (bool) $result;
 }
开发者ID:mrtnzlml,项目名称:zlml.cz,代码行数:14,代码来源:Authorizator.php

示例7: createComponentForm

 /** Vytvoření komponenty
  *
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText("login", "Přihlašovací jméno:")->setAttribute("autocomplete", "off")->setRequired("Prosím zadejte přihlašovací jméno.");
     $form->addPassword("password1", "Heslo:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $form->addPassword("password2", "Heslo pro kontrolu:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $roles = $this->roleRepository->read()->where("name != ?", "root");
     if (!$this->user->isInRole("root")) {
         $roles->where("name NOT(?)", $this->user->getRoles());
     }
     $roles = $roles->fetchPairs("aclRoleID", "name");
     $form->addSelect("role", "Oprávnění:", $roles)->setAttribute("class", "form-control");
     $form->addCheckbox("active", "Aktivní");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $form->addHidden("userID");
     $form['password2']->addRule(Form::EQUAL, 'Hesla se neshodují', $form['password1']);
     if ($this->rsuserID) {
         $userEntity = $this->userRepository->get($this->rsuserID);
         if ($userEntity) {
             $form['login']->setValue($userEntity->login);
             $form['login']->setAttribute("readonly");
             $form['userID']->setValue($this->rsuserID);
             $form['active']->setValue($userEntity->getActive());
             if ($userEntity->getUserID() == $this->user->getId()) {
                 $form['role']->setDisabled();
             }
             if ($userEntity->getLogin() != "root" && $userEntity->getUserID() !== $this->user->getId()) {
                 $form['role']->setValue($userEntity->aclRoleID);
             }
         }
     } else {
         $form['password1']->setRequired("Prosím zadejte heslo.");
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "FormError");
     return $form;
 }
开发者ID:vipercz,项目名称:sandbox,代码行数:42,代码来源:UserForm.php

示例8: baseIsAllowed

 /**
  * @param User $user
  * @param $permission
  * @return bool
  */
 private function baseIsAllowed(&$secured, &$source, &$cache, User $user, $permission)
 {
     if (!$secured) {
         return TRUE;
     }
     if (!isset($cache[$user->id][$permission])) {
         if (!isset($cache[$user->id])) {
             $cache[$user->id] = array();
         }
         if ($user->isInRole('admin')) {
             $cache[$user->id][$permission] = TRUE;
             return TRUE;
         }
         if (isset($source[$permission])) {
             $permissionEntity = $source[$permission];
             if (!$user->isLoggedIn()) {
                 $cache[$user->id][$permission] = FALSE;
                 return FALSE;
             }
             if ($permissionEntity->getAll()) {
                 $cache[$user->id][$permission] = TRUE;
                 return TRUE;
             }
             foreach ($user->getRoles() as $role) {
                 if (isset($permissionEntity->roles[$role])) {
                     $cache[$user->id][$permission] = TRUE;
                     return TRUE;
                 }
             }
         }
         $cache[$user->id][$permission] = FALSE;
     }
     return $cache[$user->id][$permission];
 }
开发者ID:svobodni,项目名称:web,代码行数:39,代码来源:PageEntity.php

示例9: getRoles

 public function getRoles() : array
 {
     return $this->user->getRoles();
 }
开发者ID:symnedi,项目名称:security,代码行数:4,代码来源:NetteTokenAdapter.php


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