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


PHP User::getId方法代码示例

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


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

示例1: isAllowed

 /**
  * Is user allowed to perform given action with given resource.
  *
  * @param mixed
  * @param string for example 'view', 'edit'
  * @return bool
  * @throws \NetteAddons\InvalidArgumentException
  */
 public function isAllowed($resource, $action)
 {
     $moderator = $this->user->isInRole('administrators') || $this->user->isInRole('moderators');
     if ($resource instanceof Addon) {
         $ownerId = $resource->userId;
         $resource = 'addon';
     } elseif ($resource instanceof \Nette\Database\Table\ActiveRow) {
         $ownerId = $resource->user->id;
         $resource = 'addon';
     } elseif ($resource == 'page' && $action == 'manage') {
         return $moderator;
     } elseif ($resource != 'addon') {
         throw new \NetteAddons\InvalidArgumentException();
     }
     if ($resource === 'addon') {
         if ($action === 'delete' || $action === 'reports') {
             return $moderator;
         }
         if ($action === 'view') {
             return TRUE;
         } elseif ($action === 'manage') {
             return $this->user->isLoggedIn() && $ownerId === $this->user->getId() || $moderator;
         } elseif ($action === 'vote') {
             // you can't vote for your own addons
             return $this->user->isLoggedIn() && $ownerId !== $this->user->getId();
         } elseif ($action === 'create') {
             return $this->user->isLoggedIn();
         }
     }
     throw new \NetteAddons\InvalidArgumentException();
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:39,代码来源:Authorizator.php

示例2: formSucceeded

 /**
  * Callback for Account Settings Form onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!$this->userManager->checkPassword($this->user->getId(), $values->current)) {
         $form->addError("Invalid current password");
     }
     $this->userManager->setNewPassword($this->user->getId(), $values->new);
 }
开发者ID:martinmayer,项目名称:notejam,代码行数:12,代码来源:AccountSettingsFormFactory.php

示例3: __invoke

 /**
  * @return mixed
  */
 public function __invoke()
 {
     if ($this->user->isLoggedIn()) {
         return $this->user->getId();
     }
     return NULL;
 }
开发者ID:darkphoenixff4,项目名称:DoctrineBehaviors,代码行数:10,代码来源:UserCallable.php

示例4: startup

 public function startup()
 {
     parent::startup();
     if ($this->user->isLoggedIn()) {
         if ($this->getParameter('id') != $this->user->getId()) {
             $this->redirect('Sign:in');
         }
     }
 }
开发者ID:04EO,项目名称:hup-nette,代码行数:9,代码来源:SecurePresenter.php

示例5: __construct

 public function __construct(Nette\Http\SessionSection $shopCart, Trejjam\Utils\Labels\Labels $labels, Nette\Security\User $user)
 {
     $this->shopCart = $shopCart;
     $this->shopCart->setExpiration('14 days');
     $this->labels = $labels;
     $this->user = $user;
     if (isset($this->shopCart->_userId) && $this->shopCart->_userId != $this->user->getId()) {
         $this->cartClear();
     }
     if (!isset($this->shopCart->_userId)) {
         $this->shopCart->_userId = $this->user->getId();
     }
 }
开发者ID:trejjam,项目名称:utils,代码行数:13,代码来源:AShopCart.php

示例6: __construct

 /**
  * @param User $user
  * @param callable|null $credentialsValidator
  */
 public function __construct(User $user, callable $credentialsValidator = null)
 {
     $this->user = $user;
     $this->credentialsValidator = $credentialsValidator ?: function () {
         $this->user->logout(true);
         try {
             $this->user->login(...func_get_args());
         } catch (\Exception $e) {
         }
         // Fail silently
         return $this->user->isLoggedIn() ? new UserEntity($this->user->getId()) : null;
     };
 }
开发者ID:lookyman,项目名称:nette-oauth2-server,代码行数:17,代码来源:UserRepository.php

示例7: formSucceeded

 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->rating->setOldSessId();
         $this->user->login($values->nick, $values->password);
         $this->rating->synchronizeUnlogged($this->user->getId());
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
开发者ID:kivi8,项目名称:ars-poetica,代码行数:15,代码来源:LogFormFactory.php

示例8: __construct

 public function __construct(DbTable\Oznam_ucast $oznam_ucast, DbTable\Oznam_volba $oznam_volba, Nette\Security\User $user)
 {
     parent::__construct();
     $this->oznam_ucast = $oznam_ucast;
     $this->oznam_volba = $oznam_volba;
     $this->id_user_profiles = $user->getId();
 }
开发者ID:petak23,项目名称:echo-msz,代码行数:7,代码来源:Potvrd_ucast.php

示例9: getEvent

 /**
  * Get event
  * @param integer $eventId
  * @return Event
  */
 public function getEvent($eventId)
 {
     // Má právo na editaci? (výchozí: ano)
     $canAccess = FALSE;
     $hasAccess = FALSE;
     $hasShare = FALSE;
     /** @var null|Event $event */
     $event = $this->eventDao->find($eventId);
     if ($event->isDeleted()) {
         throw new Nette\Application\BadRequestException($this->translator->translate('event.general.noId'));
     }
     // Is this api call?
     if ($this->user->getId() === 0) {
         $canAccess = TRUE;
     } else {
         /** @var \App\Model\Entity\User $userEntity */
         $userEntity = $this->em->getDao('\\App\\Model\\Entity\\User')->find($this->user->getId());
         /** @var \App\Model\Entity\Client $client */
         $client = $userEntity->getClient();
         // je uživatel ADMIN?
         if (($this->user->isInRole('ADMIN') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) {
             $canAccess = TRUE;
         } elseif (($this->user->isInRole('USER') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) {
             //požadavek klienta, aby šel
             $canAccess = TRUE;
         } else {
             // pokud nemá přiřazené oprávnění, má přidělené sdílení?
             if ($event->getShares() !== NULL) {
                 $hasShare = FALSE;
                 foreach ($event->getShares() as $clientShare) {
                     if ($client->getId() == $clientShare->getClient()->getId()) {
                         $hasShare = TRUE;
                         break;
                     }
                 }
             }
             // pokud ano, má přiřazená oprávnění pro event?
             if ($event->getAccesses() !== NULL) {
                 foreach ($event->getAccesses() as $clientAccess) {
                     $hasAccess = FALSE;
                     if ($client->getId() == $clientAccess->getReceiver()->getId() || $client->getId() == $clientAccess->getCreator()->getId()) {
                         $hasAccess = TRUE;
                         break;
                     }
                 }
             }
             // pokud ne, patří událost klientovi nebo sdílení, anebo přístup?
             if ($hasAccess || $hasShare) {
                 $canAccess = TRUE;
             }
         }
     }
     if ($canAccess) {
         // má přístup do události?
         return $event;
     } else {
         // jinak je přesměrován na dashboard s tím, že je upozorněn na to, že nemá oprávnění
         throw new Nette\Application\ForbiddenRequestException($this->translator->translate('event.general.noRights'));
     }
 }
开发者ID:MrTommy1979,项目名称:reference,代码行数:65,代码来源:EventService.php

示例10: 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

示例11: storeRequest

 /**
  * Stores current request to session.
  * @param  mixed  optional expiration time
  * @return string key
  */
 public function storeRequest($expiration = '+ 10 minutes')
 {
     $session = $this->getSession('Nette.Application/requests');
     do {
         $key = Nette\Utils\Random::generate(5);
     } while (isset($session[$key]));
     $session[$key] = [$this->user ? $this->user->getId() : NULL, $this->request];
     $session->setExpiration($expiration, $key);
     return $key;
 }
开发者ID:hrach,项目名称:nette-application,代码行数:15,代码来源:Presenter.php

示例12: restoreRequest

 /**
  * Restores request from session.
  * @param  string key
  * @return void
  */
 public function restoreRequest($key)
 {
     $session = $this->session->getSection('Nette.Application/requests');
     if (!isset($session[$key]) || $session[$key][0] !== NULL && $session[$key][0] !== $this->user->getId()) {
         return;
     }
     $request = clone $session[$key][1];
     unset($session[$key]);
     $request->setFlag(Application\Request::RESTORED, TRUE);
     $params = $request->getParameters();
     $params[self::FLASH_KEY] = $this->getParameter(self::FLASH_KEY);
     $request->setParameters($params);
     $this->sendResponse(new Responses\ForwardResponse($request));
 }
开发者ID:pdostal,项目名称:nette-blog,代码行数:19,代码来源:Presenter.php

示例13: 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

示例14: createComponentModerateCommentForm

 protected function createComponentModerateCommentForm()
 {
     return new Multiplier(function ($idsub) {
         $idsubArr = explode('q', $idsub);
         $id = (int) $idsubArr[0];
         $sub = $idsubArr[1] === 'false' ? false : true;
         $form = new Form();
         $comment = $this->commentsManager->getSingleComment($id, $sub);
         if (!(($comment->byUser && $comment->byUser === $this->user->getId() || $this->user->isAllowed('Comments', 'moderate')) && $this->user->isLoggedIn())) {
             return $form;
         }
         $form->getElementPrototype()->class('ajax');
         if (!$comment->byUser) {
             $form->addText('unregName', 'Neregistrované jméno')->setRequired('Zadejte jméno')->setValue($comment->unregName);
         }
         $form->addTextArea('text', 'Text')->setRequired('Zadejte text')->setValue(preg_replace('$<p>\\d{1,2}.\\d{1,2}.\\d{4} \\d{1,2}:\\d{1,2} provedena poslední změna</p>$', '', $comment->text));
         $form->addCheckbox('deleted', 'Smazaný')->setValue($comment->deleted);
         $form->addHidden('id', $id);
         $form->addHidden('sub', $sub ? 'true' : 'false');
         $form->addSubmit('moderate', 'Změnit');
         $form->onSuccess[] = [$this, 'moderateCommentFormSucceeded'];
         return $form;
     });
 }
开发者ID:kivi8,项目名称:ars-poetica,代码行数:24,代码来源:CommentsControl.php

示例15: getId

 /**
  * Return user's id.
  * @return int
  */
 public function getId()
 {
     $id = $this->user->getId();
     return $id;
 }
开发者ID:04EO,项目名称:hup-nette,代码行数:9,代码来源:SignFormFactory.php


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