本文整理汇总了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();
}
示例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);
}
示例3: __invoke
/**
* @return mixed
*/
public function __invoke()
{
if ($this->user->isLoggedIn()) {
return $this->user->getId();
}
return NULL;
}
示例4: startup
public function startup()
{
parent::startup();
if ($this->user->isLoggedIn()) {
if ($this->getParameter('id') != $this->user->getId()) {
$this->redirect('Sign:in');
}
}
}
示例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();
}
}
示例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;
};
}
示例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());
}
}
示例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();
}
示例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'));
}
}
示例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);
}
}
示例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;
}
示例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));
}
示例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;
}
示例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;
});
}
示例15: getId
/**
* Return user's id.
* @return int
*/
public function getId()
{
$id = $this->user->getId();
return $id;
}