本文整理汇总了PHP中User::can方法的典型用法代码示例。如果您正苦于以下问题:PHP User::can方法的具体用法?PHP User::can怎么用?PHP User::can使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::can方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submit
public function submit($problem_id)
{
try {
$problem = new Problem($problem_id);
$language = fRequest::get('language', 'integer');
if (!array_key_exists($language, static::$languages)) {
throw new fValidationException('Invalid language.');
}
fSession::set('last_language', $language);
$code = trim(fRequest::get('code', 'string'));
if (strlen($code) == 0) {
throw new fValidationException('Code cannot be empty.');
}
if ($problem->isSecretNow()) {
if (!User::can('view-any-problem')) {
throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.');
}
}
$record = new Record();
$record->setOwner(fAuthorization::getUserToken());
$record->setProblemId($problem->getId());
$record->setSubmitCode($code);
$record->setCodeLanguage($language);
$record->setSubmitDatetime(Util::currentTime());
$record->setJudgeStatus(JudgeStatus::PENDING);
$record->setJudgeMessage('Judging... PROB=' . $problem->getId() . ' LANG=' . static::$languages[$language]);
$record->setVerdict(Verdict::UNKNOWN);
$record->store();
Util::redirect('/status');
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('code', '/submit', fRequest::get('code', 'string'));
Util::redirect("/submit?problem={$problem_id}");
}
}
示例2: homework
public function homework()
{
if (fAuthorization::checkLoggedIn()) {
$this->cache_control('private', 5);
} else {
$this->cache_control('private', 10);
}
$conditions = array('title~' => array('homework', '作业'));
if (!User::can('view-any-report')) {
$conditions['visible='] = TRUE;
}
$this->reports = fRecordSet::build('Report', $conditions, array('id' => 'desc'));
$this->nav_class = 'homework';
$this->render('report/homework');
}
示例3: run
function run()
{
$this->events->add_filter('admin_menus', function ($menus) {
if (User::can($this->privilege)) {
$menus[$this->namespace] = array(array('title' => $this->label, 'href' => '#', 'disable' => true, 'icon' => $this->menu_icon), array('title' => $this->posts_list_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'list'))), array('title' => $this->new_post_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'new'))));
if ($this->comment_enabled === TRUE) {
$menus[$this->namespace][] = array('title' => $this->post_comment_label, 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'comments')));
}
foreach (force_array($this->query->get_defined_taxonomies()) as $taxonomy) {
$menus[$this->namespace][] = array('title' => riake('taxonomy-list-label', $taxonomy, sprintf(__('%s list'), riake('namespace', $taxonomy))), 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'taxonomy', riake('namespace', $taxonomy), 'list')));
$menus[$this->namespace][] = array('title' => riake('new-taxonomy-label', $taxonomy, sprintf(__('New %s'), riake('namespace', $taxonomy))), 'href' => site_url(array('dashboard', 'posttype', $this->namespace, 'taxonomy', riake('namespace', $taxonomy), 'new')));
}
}
return $menus;
});
}
示例4: show
public function show($id)
{
if (fAuthorization::checkLoggedIn()) {
$this->cache_control('private', 30);
} else {
$this->cache_control('private', 60);
}
try {
$this->problem = new Problem($id);
if ($this->problem->isSecretNow()) {
if (!User::can('view-any-problem')) {
throw new fAuthorizationException('Problem is secret now.');
}
}
$this->nav_class = 'problems';
$this->render('problem/show');
} catch (fExpectedException $e) {
fMessaging::create('warning', $e->getMessage());
fURL::redirect(Util::getReferer());
} catch (fUnexpectedException $e) {
fMessaging::create('error', $e->getMessage());
fURL::redirect(Util::getReferer());
}
}
示例5: showForUser
/**
* Show rights of a user
*
* @param $user User object
**/
static function showForUser(User $user)
{
global $DB, $CFG_GLPI, $LANG;
$ID = $user->getField('id');
if (!$user->can($ID, 'r')) {
return false;
}
$canedit = $user->can($ID, 'w');
$strict_entities = self::getUserEntities($ID, false);
if (!haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
$canedit = false;
}
$canshowentity = haveRight("entity", "r");
$rand = mt_rand();
echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
echo getItemTypeFormURL(__CLASS__) . "'>";
if ($canedit) {
echo "<div class='firstbloc'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['setup'][605] . "</tr>";
echo "<tr class='tab_bg_2'><td class='center'>";
echo "<input type='hidden' name='users_id' value='{$ID}'>";
Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities']));
echo "</td><td class='center'>" . $LANG['profiles'][22] . " : ";
Profile::dropdownUnder(array('value' => Profile::getDefault()));
echo "</td><td class='center'>" . $LANG['profiles'][28] . " : ";
Dropdown::showYesNo("is_recursive", 0);
echo "</td><td class='center'>";
echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
echo "</td></tr>";
echo "</table></div>";
}
echo "<div class='spaced'><table class='tab_cadre_fixehov'>";
echo "<tr><th colspan='2'>" . $LANG['Menu'][37] . "</th>";
echo "<th>" . $LANG['profiles'][22] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")";
echo "</th></tr>";
$query = "SELECT DISTINCT `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles`.`id`,\n `glpi_profiles`.`name`,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`,\n `glpi_entities`.`completename`,\n `glpi_profiles_users`.`entities_id`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_profiles_users`.`entities_id` = `glpi_entities`.`id`)\n WHERE `glpi_profiles_users`.`users_id` = '{$ID}'\n ORDER BY `glpi_profiles`.`name`, `glpi_entities`.`completename`";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_array($result)) {
echo "<tr class='tab_bg_1'>";
echo "<td width='10'>";
if ($canedit && in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>";
} else {
echo " ";
}
echo "</td>";
if ($data["entities_id"] == 0) {
$data["completename"] = $LANG['entity'][2];
}
echo "<td>";
if ($canshowentity) {
echo "<a href='" . getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
}
echo $data["completename"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["entities_id"] . ")" : "");
if ($canshowentity) {
echo "</a>";
}
echo "</td>";
echo "<td>" . $data["name"];
if ($data["is_dynamic"] || $data["is_recursive"]) {
echo "<strong> (";
if ($data["is_dynamic"]) {
echo "D";
}
if ($data["is_dynamic"] && $data["is_recursive"]) {
echo ", ";
}
if ($data["is_recursive"]) {
echo "R";
}
echo ")</strong>";
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
if ($canedit) {
openArrowMassive("entityuser_form{$rand}", true);
closeArrowMassive('delete', $LANG['buttons'][6]);
}
echo "</form></div>";
}
示例6: showAddEmailButton
/**
* @param $user
**/
static function showAddEmailButton(User $user)
{
$users_id = $user->getID();
if (!$user->can($users_id, READ) && $users_id != Session::getLoginUserID()) {
return false;
}
$canedit = $user->can($users_id, UPDATE) || $users_id == Session::getLoginUserID();
parent::showAddChildButtonForItemForm($user, '_useremails', $canedit);
return;
}
示例7: switch
$_POST["start"] = 0;
}
if (!isset($_POST["sort"])) {
$_POST["sort"] = "";
}
if (!isset($_POST["order"])) {
$_POST["order"] = "";
}
if (empty($_POST["id"]) && isset($_POST["name"])) {
$user->getFromDBbyName($_POST["name"]);
glpi_header($CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $user->fields['id']);
}
if (empty($_POST["name"])) {
$_POST["name"] = "";
}
if ($_POST["id"] > 0 && $user->can($_POST["id"], 'r')) {
switch ($_REQUEST['glpi_tab']) {
case -1:
Profile_User::showForUser($user);
Group_User::showForUser($user);
$config = new Config();
$user->computePreferences();
$config->showFormUserPrefs($user->fields);
$user->showItems();
Reservation::showForUser($_POST["id"]);
Ticket::showListForUser($_POST["id"]);
Plugin::displayAction($user, $_REQUEST['glpi_tab']);
break;
case 2:
$user->showItems();
break;
示例8: comment_checks
/**
* @param int $image_id
* @param User $user
* @param string $comment
* @throws CommentPostingException
*/
private function comment_checks($image_id, User $user, $comment)
{
global $config, $page;
// basic sanity checks
if (!$user->can("create_comment")) {
throw new CommentPostingException("Anonymous posting has been disabled");
} else {
if (is_null(Image::by_id($image_id))) {
throw new CommentPostingException("The image does not exist");
} else {
if (trim($comment) == "") {
throw new CommentPostingException("Comments need text...");
} else {
if (strlen($comment) > 9000) {
throw new CommentPostingException("Comment too long~");
} else {
if (strlen($comment) / strlen(gzcompress($comment)) > 10) {
throw new CommentPostingException("Comment too repetitive~");
} else {
if ($user->is_anonymous() && !$this->hash_match()) {
$page->add_cookie("nocache", "Anonymous Commenter", time() + 60 * 60 * 24, "/");
throw new CommentPostingException("Comment submission form is out of date; refresh the " . "comment form to show you aren't a spammer~");
} else {
if ($this->is_comment_limit_hit()) {
throw new CommentPostingException("You've posted several comments recently; wait a minute and try again...");
} else {
if ($this->is_dupe($image_id, $comment)) {
throw new CommentPostingException("Someone already made that comment on that image -- try and be more original?");
} else {
if ($config->get_bool('comment_captcha') && !captcha_check()) {
throw new CommentPostingException("Error in captcha");
} else {
if ($user->is_anonymous() && $this->is_spam_akismet($comment)) {
throw new CommentPostingException("Akismet thinks that your comment is spam. Try rewriting the comment, or logging in.");
}
}
}
}
}
}
}
}
}
}
}
示例9: showForUser
/**
* Show rights of a user
*
* @param $user User object
**/
static function showForUser(User $user)
{
global $DB, $CFG_GLPI;
$ID = $user->getField('id');
if (!$user->can($ID, READ)) {
return false;
}
$canedit = $user->canEdit($ID);
$strict_entities = self::getUserEntities($ID, false);
if (!Session::haveAccessToOneOfEntities($strict_entities) && !Session::isViewAllEntities()) {
$canedit = false;
}
$canshowentity = Entity::canView();
$rand = mt_rand();
if ($canedit) {
echo "<div class='firstbloc'>";
echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>";
echo "<tr class='tab_bg_2'><td class='center'>";
echo "<input type='hidden' name='users_id' value='{$ID}'>";
Entity::dropdown(array('entity' => $_SESSION['glpiactiveentities']));
echo "</td><td class='center'>" . self::getTypeName(1) . "</td><td>";
Profile::dropdownUnder(array('value' => Profile::getDefault()));
echo "</td><td>" . __('Recursive') . "</td><td>";
Dropdown::showYesNo("is_recursive", 0);
echo "</td><td class='center'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
echo "</td></tr>";
echo "</table>";
Html::closeForm();
echo "</div>";
}
$query = "SELECT DISTINCT `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles`.`id`,\n `glpi_profiles`.`name`,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`,\n `glpi_entities`.`completename`,\n `glpi_profiles_users`.`entities_id`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_profiles_users`.`entities_id` = `glpi_entities`.`id`)\n WHERE `glpi_profiles_users`.`users_id` = '{$ID}'\n ORDER BY `glpi_profiles`.`name`, `glpi_entities`.`completename`";
$result = $DB->query($query);
$num = $DB->numrows($result);
echo "<div class='spaced'>";
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
if ($canedit && $num) {
$massiveactionparams = array('num_displayed' => $num, 'container' => 'mass' . __CLASS__ . $rand);
Html::showMassiveActions($massiveactionparams);
}
if ($num > 0) {
echo "<table class='tab_cadre_fixehov'>";
$header_begin = "<tr>";
$header_top = '';
$header_bottom = '';
$header_end = '';
if ($canedit) {
$header_begin .= "<th>";
$header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
$header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
$header_end .= "</th>";
}
$header_end .= "<th>" . _n('Entity', 'Entities', Session::getPluralNumber()) . "</th>";
$header_end .= "<th>" . sprintf(__('%1$s (%2$s)'), self::getTypeName(Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
$header_end .= "</th></tr>";
echo $header_begin . $header_top . $header_end;
while ($data = $DB->fetch_assoc($result)) {
echo "<tr class='tab_bg_1'>";
if ($canedit) {
echo "<td width='10'>";
if (in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
} else {
echo " ";
}
echo "</td>";
}
echo "<td>";
$link = $data["completename"];
if ($_SESSION["glpiis_ids_visible"]) {
$link = sprintf(__('%1$s (%2$s)'), $link, $data["entities_id"]);
}
if ($canshowentity) {
echo "<a href='" . Toolbox::getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
}
echo $link . ($canshowentity ? "</a>" : '');
echo "</td>";
if (Profile::canView()) {
$entname = "<a href='" . Toolbox::getItemTypeFormURL('Profile') . "?id=" . $data["id"] . "'>" . $data["name"] . "</a>";
} else {
$entname = $data["name"];
}
if ($data["is_dynamic"] || $data["is_recursive"]) {
$entname = sprintf(__('%1$s %2$s'), $entname, "<span class='b'>(");
if ($data["is_dynamic"]) {
//TRANS: letter 'D' for Dynamic
$entname = sprintf(__('%1$s%2$s'), $entname, __('D'));
}
if ($data["is_dynamic"] && $data["is_recursive"]) {
$entname = sprintf(__('%1$s%2$s'), $entname, ", ");
}
if ($data["is_recursive"]) {
//.........这里部分代码省略.........
示例10: managePermission
public function managePermission($action)
{
try {
$user_name = fRequest::get('user_name');
$permission_name = fRequest::get('permission_name');
if ($action == 'Add') {
if (User::can('add-permission')) {
$permission = new Permission();
$permission->setUserName($user_name);
$permission->setPermissionName($permission_name);
$permission->store();
fMessaging::create('success', 'Permission added successfully.');
} else {
throw new fAuthorizationException('You are not allowed to add permissions.');
}
} else {
if ($action == 'Remove') {
if (User::can('remove-permission')) {
$permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name));
$permission->delete();
fMessaging::create('success', 'Permission removed successfully.');
} else {
throw new fAuthorizationException('You are not allowed to remove permissions.');
}
}
}
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
}
fURL::redirect(Util::getReferer());
}
示例11: foreach
}
?>
</ul>
<?php
foreach ($this->variables as $v) {
?>
<h3 id="<?php
echo fHTML::encode($v->getName());
?>
"><?php
echo fHTML::prepare($v->getName());
?>
</h3>
<a href="#variables">[list]</a>
<?php
if (User::can('set-variable')) {
?>
<a href="?edit=<?php
echo fHTML::encode($v->getName());
?>
#set_variable">[edit]</a>
<a href="?remove=<?php
echo fHTML::encode($v->getName());
?>
#set_variable">[remove]</a>
<?php
}
?>
<pre><?php
echo fHTML::encode($v->getValue());
?>
示例12: groups
/**
* Admin Roles
*
* Handle Groups management
* @since 1.5
**/
function groups($page = 'list', $index = 1)
{
// Display all roles
if ($page == 'list') {
$groups = $this->users->auth->list_groups();
$this->gui->set_title(sprintf(__('Roles — %s'), get('core_signature')));
$this->load->view('../modules/aauth/views/groups/body', array('groups' => $groups));
} else {
if ($page == 'new') {
if (!User::can('manage_users')) {
redirect(array('dashboard?notice=access-denied'));
}
// permission checks
// Validating role creation form
$this->load->library('form_validation');
$this->form_validation->set_rules('role_name', __('Role Name'), 'required');
$this->form_validation->set_rules('role_type', __('Role Type'), 'required');
if ($this->form_validation->run()) {
$exec = $this->users->set_group($this->input->post('role_name'), $this->input->post('role_definition'), $this->input->post('role_type'));
if ($exec == 'group-created') {
redirect(array('dashboard', 'groups?notice=' . $exec));
}
$this->notice->push_notice($this->lang->line($exec));
}
$this->gui->set_title(sprintf(__('Create new role — %s'), get('core_signature')));
$this->load->view('../modules/aauth/views/groups/create');
} else {
if ($page == 'edit') {
if (!User::can('manage_users')) {
redirect(array('dashboard?notice=access-denied'));
}
// permission checks
$this->load->library('form_validation');
$this->form_validation->set_rules('role_name', __('Role Name'), 'required');
$this->form_validation->set_rules('role_type', __('Role Type'), 'required');
if ($this->form_validation->run()) {
$exec = $this->users->set_group($this->input->post('role_name'), $this->input->post('role_definition'), $this->input->post('role_type'), 'edit', $index);
if ($exec == 'group-updated') {
redirect(current_url() . '?notice=' . $exec);
}
$this->notice->push_notice($this->lang->line($exec));
}
// Fetch role or redirect
$group = $this->users->auth->get_group_id($index);
if (is_object($group) === FALSE) {
redirect(array('dashboard', 'group-not-found'));
}
$usergroup = $this->users->auth->get_user_groups($index);
$this->gui->set_title(sprintf(__('Edit Roles — %s'), get('core_signature')));
$this->load->view('../modules/aauth/views/groups/edit', array('group' => $group));
}
}
}
}
示例13: isReadable
public function isReadable()
{
return fAuthorization::getUserToken() == $this->getOwner() or User::can('view-any-record');
}
示例14: user_can_edit_user
/**
* @param User $a
* @param User $b
* @return bool
*/
private function user_can_edit_user(User $a, User $b)
{
if ($a->is_anonymous()) {
$this->theme->display_error(401, "Error", "You aren't logged in");
return false;
}
if ($a->name == $b->name || $b->can("protected") && $a->class->name == "admin" || !$b->can("protected") && $a->can("edit_user_info")) {
return true;
} else {
$this->theme->display_error(401, "Error", "You need to be an admin to change other people's details");
return false;
}
}
示例15: link_to_destroy
function link_to_destroy(&$record)
{
if (User::can('destroy action', 'Admin::Users') && $this->_controller->CurrentUser->id != $record->id && (User::can('Edit other users', 'Admin::Users') || $this->_controller->CurrentUser->id == $record->id)) {
return $this->_controller->url_helper->link_to($this->_controller->t('Delete'), array('action' => 'destroy', 'id' => $record->getId()), array('class' => 'action'));
}
}