本文整理汇总了PHP中Nette\Security\User::isAllowed方法的典型用法代码示例。如果您正苦于以下问题:PHP User::isAllowed方法的具体用法?PHP User::isAllowed怎么用?PHP User::isAllowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Security\User
的用法示例。
在下文中一共展示了User::isAllowed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addItem
/**
* Add menu item
* @param string $title Text in anchor
* @param string $module destination module
* @param string $presenter destination presenter
* @param string $action destination action
* @param string $auth resource for authorizator
* @param boolean $clickable is anchor clickable?
* @return void
*/
public function addItem($title, $module, $presenter, $action, $auth, $clickable = true)
{
if ($this->user->isAllowed($auth, "view")) {
$this->items[] = array("title" => $title, "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable);
}
return;
}
示例2: Submit
/**
* @param Form $form
*/
public function Submit(Form $form)
{
$json = new \stdClass();
$json->result = "success";
$values = $form->getValues();
$result = false;
if (!empty($values['userID'])) {
$userEntity = $this->userRepository->get($values['userID']);
if ($userEntity) {
if ($this->user->isAllowed("user_management", "edit")) {
$userEntity->setLogin($values['login']);
if (!empty($values['password1'])) {
$userEntity->setPassword($values['password1']);
}
if ($userEntity->getLogin() !== "root" && $userEntity->getUserID() !== $this->user->getId()) {
$userEntity->setActive($values['active']);
if ($userEntity->getRole()->getAclRoleID() != $this->user->getIdentity()->data['aclRoleID']) {
$userEntity->setAclRoleID($values['role']);
}
}
try {
$result = $this->userRepository->save();
} catch (\PDOException $e) {
$result = $e->getMessage();
}
} else {
$result = UserForm::PERMISSION;
}
}
} else {
if ($this->user->isAllowed("user_management", "add")) {
$userEntity = new UserEntity();
$userEntity->setLogin($values['login'])->setPassword($values['password1'])->setActive($values['active'])->setAclRoleID($values['role']);
try {
$result = $this->userRepository->push($userEntity)->save();
} catch (\PDOException $e) {
$result = $e->getMessage();
if (preg_match("/Duplicate entry/", $result)) {
$result = "Nick <strong>" . $values['login'] . "</strong> již existuje. Zvolte prosím jiný login.";
}
}
if ($result instanceof UserEntity || $result === TRUE) {
$result = TRUE;
}
} else {
$result = UserForm::PERMISSION;
}
}
if ($result === TRUE) {
$json->result = "success";
} else {
$json->result = "error";
$json->message = $result;
}
$response = new JsonResponse($json);
$this->getPresenter()->sendResponse($response);
}
示例3: addItem
/**
* Add menu item
* @param string $title Text in anchor
* @param string $module destination module
* @param string $presenter destination presenter
* @param string $action destination action
* @param string $auth resource for authorizator
* @param boolean $clickable is anchor clickable?
* @return void
*/
public function addItem($title, $module, $presenter, $action, $auth, $clickable = true, $params = null)
{
if ($this->user->isAllowed($auth, "view")) {
if ($params != null) {
$this->items[] = array("title" => _($title), "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable, "params" => $params);
} else {
$this->items[] = array("title" => _($title), "module" => $module, "presenter" => $presenter, "action" => $action, "clickable" => $clickable);
}
}
return;
}
示例4: Submit
/** Submit
*
* @param \Nette\Application\UI\Form $form
*/
public function Submit(Form $form)
{
$json = new \stdClass();
$json->result = "success";
$values = $form->getValues();
if (!empty($values['aclActionID'])) {
if ($this->user->isAllowed("permission", "edit")) {
$actionEntity = $this->actionRepository->get($values['aclActionID']);
if ($actionEntity) {
$actionEntity->setName($values['name']);
$actionEntity->setHumanName($values['humanName']);
try {
$result = $this->actionRepository->save();
} catch (\PDOException $e) {
$result = $e->getMessage();
}
} else {
$result = FALSE;
}
} else {
$result = ActionForm::PERMISSION;
}
} else {
if ($this->user->isAllowed("permission", "add")) {
$actionEntity = new ActionEntity();
$actionEntity->setName($values['name']);
$actionEntity->setHumanName($values['humanName']);
try {
$ent = $this->actionRepository->push($actionEntity)->save();
if ($ent instanceof ActionEntity || $ent === TRUE) {
$result = TRUE;
} else {
$result = FALSE;
}
} catch (\PDOException $e) {
$result = $e->getMessage();
}
} else {
$result = ActionForm::PERMISSION;
}
}
if ($result === TRUE) {
$json->result = "success";
} else {
$json->result = "error";
$json->message = $result;
}
$response = new JsonResponse($json);
$this->getPresenter()->sendResponse($response);
}
示例5: getArticles
/**
* @return Article[]
*/
public function getArticles() : array
{
$articleFullPath = $this->getArticleFullPath();
$result = Finder::findDirectories('*/*/*')->from($articleFullPath);
$articles = [];
foreach ($result as $articleDirectory) {
/** @var SplFileInfo $articleDirectory */
$relativePath = $this->parseRelativePath($articleDirectory);
$article = $this->articleBuilder->getArticleFromMeta($articleDirectory, $relativePath);
if ($this->userContext->isAllowed($article, Article::PERMISSION_VIEW)) {
$articles[] = $article;
}
}
return $articles;
}
示例6: _panelPrihlaseny
/**
* Panel prihlaseneho uzivatela
* @param string $baseUrl
* @param string $log_out
* @return \App\FrontModule\Components\User\MenuItem */
private function _panelPrihlaseny($baseUrl, $log_out)
{
$menu_user = [];
$udata = $this->user->getIdentity();
if ($this->nastavenie['view_avatar']) {
$obb = Html::el('img class="avatar"');
if ($udata->avatar_25 && is_file('www/' . $udata->avatar_25)) {
$obb = $obb->src($baseUrl . '/www/' . $udata->avatar_25)->alt('avatar');
} else {
$obb = $obb->src($baseUrl . '/www/ikonky/64/figurky_64.png')->alt('bez avatara');
}
} else {
$obb = "";
}
$menu_user[] = new MenuItem(['odkaz' => 'UserLog:', 'nazov' => $obb . " " . $udata->meno . ' ' . $udata->priezvisko, 'title' => $udata->meno . ' ' . $udata->priezvisko]);
if ($this->user->isAllowed('admin', 'enter')) {
$menu_user[] = new MenuItem(['odkaz' => ':Admin:Homepage:', 'title' => 'Administrácia', 'ikonka' => $this->nastavenie['admin_link'] & 1 ? 'pencil' : '', 'nazov' => $this->nastavenie['admin_link'] & 2 ? $this->texty['base_AdminLink_name'] : '']);
}
if ($this->user->isInRole('admin')) {
$hl_m_db_info = $this->lang->getDBInfo();
$menu_user[] = new MenuItem(['abs_link' => $baseUrl . "/www/adminer/?server=" . $hl_m_db_info['host'] . "&db=" . $hl_m_db_info['dbname'], 'title' => 'Adminer', 'target' => '_blank', 'nazov' => Html::el('img')->src($baseUrl . '/www/ikonky/16/graf_16.png')->alt('Adminer')]);
}
$menu_user[] = new MenuItem(['odkaz' => 'signOut!', 'ikonka' => "sign-out", 'nazov' => $log_out]);
return $menu_user;
}
示例7: Submit
/** Submit
*
* @param \Nette\Application\UI\Form $form
*/
public function Submit(Form $form)
{
$json = new \stdClass();
$json->result = "success";
$values = $form->getValues();
if (array_search(TRUE, (array) $values["actions"]) === FALSE) {
$json->result = "error";
$json->message = "Prosím vyberte alespoň jednu akci pro modul.";
} else {
if (!empty($values['aclResourceID'])) {
if ($this->user->isAllowed("permission", "edit")) {
$result = $this->modelManager->update($values);
} else {
$result = ResourceForm::PERMISSION;
}
} else {
if ($this->user->isAllowed("permission", "add")) {
$result = $this->modelManager->insert($values);
} else {
$result = ResourceForm::PERMISSION;
}
}
if ($result === TRUE) {
$json->result = "success";
} else {
$json->result = "error";
$json->message = $result;
}
}
$response = new JsonResponse($json);
$this->getPresenter()->sendResponse($response);
}
示例8: 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);
}
}
示例9: Submit
/** Submit
*
* @param \Nette\Application\UI\Form $form
*/
public function Submit(Form $form)
{
$json = new \stdClass();
$json->result = "success";
$values = $form->getValues();
if (!empty($values['aclRoleID'])) {
if ($this->user->isAllowed("permission", "edit")) {
$result = $this->permissionManager->update($values);
} else {
$result = RoleForm::PERMISSION;
}
} else {
if ($this->user->isAllowed("permission", "add")) {
$result = $this->permissionManager->insert($values);
} else {
$result = RoleForm::PERMISSION;
}
}
/*Debugger::dump($values);
exit();*/
if ($result === TRUE) {
$json->result = "success";
} else {
$json->result = "error";
$json->message = $result;
}
$response = new JsonResponse($json);
$this->getPresenter()->sendResponse($response);
}
示例10: checkResources
protected function checkResources($element)
{
if ($element->hasAnnotation('resource')) {
$resources = (array) $element->getAnnotation('resource');
if (count($resources) != 1) {
throw new InvalidStateException('Invalid annotation resource count!');
}
foreach ($resources as $resource) {
if ($this->user->isAllowed($resource)) {
return true;
}
}
return false;
}
return true;
}
示例11: render
public function render()
{
$this->template->setFile(__DIR__ . '/ServerList.latte');
if ($this->user) {
$this->template->servers = $this->serverRepo->findBy(array('user_id' => $this->user->id));
$this->template->userId = $this->user;
$this->template->allowedToStop = $this->user->isAllowed('commands', 'edit');
$this->template->allowedToDelete = $this->user->isAllowed('delete', 'edit');
} else {
$this->template->servers = $this->serverRepo->findAll();
$this->template->userId = FALSE;
$this->template->allowedToStop = TRUE;
$this->template->allowedToDelete = TRUE;
}
$this->template->servers->order('id');
$this->template->registerHelper('getVersion', '\\gameUpdateModel::getVersionFromFileName');
$this->template->render();
}
示例12: __construct
public function __construct(array $config, Nette\Security\User $user)
{
parent::__construct($config);
$this->processPattern(function ($value, $key) {
return $value === NULL;
}, function ($value, $key) use($user) {
return $user->isAllowed('WebContent', 'Edit');
});
}
示例13: addItems
/**
* Make menu from config.neon
* @return void
*/
public function addItems()
{
foreach ($this->data as $data) {
if ($data["module"] . ":" . $data["presenter"] == $this->currentPresenter && $data["action"] == $this->currentAction) {
$clickable = false;
} else {
$clickable = true;
}
$this->addItem($data["title"], $data["module"], $data["presenter"], $data["action"], $data["auth"], $clickable);
}
if ($this->user->isAllowed("user", "view")) {
if (!isset($this->user->getIdentity()->isSSLlogin) or $this->user->getIdentity()->isSSLlogin == false) {
$this->addItem(_("Logout"), "User", "Authenticator", "logout", "user", true);
} else {
$this->addItem(_("SSL Login"), "User", "Authenticator", "logout", "user", false);
}
}
return;
}
示例14: create
private function create()
{
$form = new Form();
$form->addText('title', 'Titulek')->setRequired('Zadejte titulek')->setAttribute('placeholder', 'Zadejte titulek');
if ($this->user->isAllowed(self::RES, 'moderate')) {
$users = $this->userManager->getUserList();
$form->addSelect('byUser', 'Za uživatele', ['0' => 'Neregistrovaný'] + $users['deleted'] + $users['allowed'])->setValue($this->user->id);
$form->addText('byUnregUser', 'Za neregistrovaného uživatele');
}
$form->addTextArea('description', 'Popis')->setRequired('Zadejte popis');
$form->addTextArea('text', 'Článek')->setRequired('Zadejte článek');
$form->addText('keyWords', 'Klíčová slova');
$form->addCheckbox('commentsAllow', 'Povolit komentáře');
$form->addCheckbox('voteAllow', 'Povolit hlasování');
$form->addUpload('photo', 'Náhledová fotka');
if ($this->setSection) {
$form->addSelect('underSection', 'Hlavní sekce', $this->articleManager->getMainSectionList())->setValue($this->setSection);
if ($this->setSubsection) {
$form->addSelect('underSubSection', 'Podsekce', $this->articleManager->getSubSectionList($this->setSection))->setValue($this->setSubsection);
if ($this->setSerial) {
$form->addSelect('underSerial', 'Serial', $this->articleManager->getSerialList($this->setSubsection))->setValue($this->setSerial);
} else {
$form->addSelect('underSerial', 'Serial', $this->articleManager->getSerialList($this->setSubsection))->setPrompt('Vyberte');
}
} else {
$form->addSelect('underSubSection', 'Podsekce', $this->articleManager->getSubSectionList($this->setSection))->setPrompt('Vyberte podsekci');
$form->addSelect('underSerial', 'Serial')->setPrompt('Vyberte podsekci');
}
} else {
$form->addSelect('underSection', 'Hlavní sekce', $this->articleManager->getMainSectionList())->setPrompt('Vyberte hlavní sekci');
$form->addSelect('underSubSection', 'Podsekce')->setPrompt('Vyberte hlavní sekci');
$form->addSelect('underSerial', 'Serial')->setPrompt('Vyberte hlavní sekci');
}
if ($this->user->isAllowed('Section', 'moderate')) {
}
if ($this->user->isAllowed(self::RES, 'publish')) {
$form->addCheckbox('published', 'Publikovaný ihned');
}
$form->addSubmit('submitArticle', 'Odeslat')->setValidationScope(false);
return $form;
}
示例15: isAllowed
public function isAllowed($resource = IAuthorizator::ALL, $privilege = IAuthorizator::ALL)
{
$isAllowed = parent::isAllowed($resource, $privilege);
if (is_array($resource)) {
@(list($resource, $type) = $resource);
// @ intentionally
}
if ($resource instanceof IUserAccessibleEntity && $isAllowed === FALSE) {
return $resource->checkAccess($this->id, $privilege);
}
return $isAllowed;
}