本文整理汇总了PHP中hasPermission函数的典型用法代码示例。如果您正苦于以下问题:PHP hasPermission函数的具体用法?PHP hasPermission怎么用?PHP hasPermission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hasPermission函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Submit a comment to an article
* @param Int $id
*/
public function add($id = false)
{
requirePermission("canAddComment");
if (!$id) {
die;
}
// Check if article exist and if you can comment it
if ($this->news_model->articleExists($id, true) && $this->user->isOnline()) {
$message = $this->input->post('content');
if (strlen($message) > 0 && $message && strlen($message) <= 255) {
// Format the comment
$comment = array("timestamp" => time(), "article_id" => $id, "author_id" => $this->user->getId(), "content" => $message, "is_gm" => hasPermission('postCommentAsStaff') ? 1 : 0);
$this->comments_model->addComment($comment);
// Add log
$this->logger->createLog('Added comment', $id);
$this->plugins->onAddComment($id, $message);
// Get last comment
$comment_arr = $this->comments_model->getLastComment($id);
// Add values
$comment_arr['profile'] = $this->template->page_url . "profile/" . $comment_arr['author_id'];
$comment_arr['avatar'] = $this->user->getAvatar($comment_arr['author_id'], "small");
$comment_arr['author'] = $this->user->getNickname($comment_arr['author_id']);
$comment_arr['content'] = $this->template->format($message, true, true, true, 45);
$comment_arr['url'] = $this->template->page_url;
$comment_arr['is_gm'] = $comment['is_gm'];
// Clear cache
$this->cache->delete('news_*.cache');
$this->cache->delete('comments_' . $id . '_*.cache');
// Load the comment template, also check if we are a staff member
$data = array('comments' => array($comment_arr), 'user_is_gm' => hasPermission('postCommentAsStaff'), 'url' => $this->template->page_url);
die($this->template->loadPage("comments.tpl", $data));
}
}
}
示例2: get
public function get($id = false)
{
// Is it loaded via ajax or not?
if ($id === false) {
$id = 0;
$die = false;
} else {
$die = true;
}
$cache = $this->cache->get("shoutbox_" . $id . "_" . getLang());
if ($cache !== false) {
$shouts = $cache;
} else {
// Load the shouts
$shouts = $this->shoutbox_model->getShouts($id, $this->config->item('shouts_per_page'));
// Format the shout data
foreach ($shouts as $key => $value) {
$shouts[$key]['nickname'] = $this->internal_user_model->getNickname($shouts[$key]['author']);
$shouts[$key]['content'] = $this->template->format($shouts[$key]['content'], true, true, true, 40);
}
$this->cache->save("shoutbox_" . $id . "_" . getLang(), $shouts);
}
foreach ($shouts as $key => $value) {
$shouts[$key]['date'] = $this->template->formatTime(time() - $shouts[$key]['date']);
}
// Prepare the data
$data = array("module" => "sidebox_shoutbox", "shouts" => $shouts, "url" => $this->template->page_url, "user_is_gm" => hasPermission("removeShout", "sidebox_shoutbox"));
$shouts = $this->template->loadPage("shouts.tpl", $data);
// To be or not to be, that's the question :-)
if ($die) {
die($shouts);
} else {
return $shouts;
}
}
示例3: __construct
public function __construct()
{
parent::__construct();
if (!hasPermission('access_help_page')) {
redirect(BASE_URL . 'dashboard/');
}
}
示例4: index
public function index()
{
requirePermission("view");
$this->template->setTitle(lang("user_panel", "ucp"));
$cache = $this->cache->get("profile_characters_" . $this->user->getId());
if ($cache !== false) {
$characters = $cache;
} else {
$characters_data = array("characters" => $this->realms->getTotalCharacters(), "realms" => $this->realms->getRealms(), "url" => $this->template->page_url, "realmObj" => $this->realms);
$characters = $this->template->loadPage("ucp_characters.tpl", $characters_data);
$this->cache->save("profile_characters_" . $this->user->getId(), $characters, 60 * 60);
}
$links = $this->menu_model->getMenuLinks();
if ($links) {
foreach ($links as $key => $value) {
// Check if we have the permission, otherwise unset the row
if ($value['permission'] != '') {
if (hasPermission($value['permission'], $value['permissionModule']) !== true) {
unset($links[$key]);
continue;
}
}
// Add the website path if internal link
if (!preg_match("/https?:\\/\\//", $value['link'])) {
$links[$key]['link'] = $this->template->page_url . $value['link'];
}
$links[$key]['name'] = langColumn($links[$key]['name']);
}
}
$data = array("username" => $this->user->getNickname(), "expansion" => $this->realms->getEmulator()->getExpansionName($this->external_account_model->getExpansion()), "vp" => $this->internal_user_model->getVp(), "dp" => $this->internal_user_model->getDp(), "url" => $this->template->page_url, "location" => $this->internal_user_model->getLocation(), "groups" => $this->acl_model->getGroupsByUser($this->user->getId()), "register_date" => $this->user->getRegisterDate(), "status" => $this->user->getAccountStatus(), "characters" => $characters, "avatar" => $this->user->getAvatar($this->user->getId()), "id" => $this->user->getId(), "menu_links" => $links, "config" => array("vote" => $this->config->item('ucp_vote'), "donate" => $this->config->item('ucp_donate'), "store" => $this->config->item('ucp_store'), "settings" => $this->config->item('ucp_settings'), "expansion" => $this->config->item('ucp_expansion'), "teleport" => $this->config->item('ucp_teleport'), "admin" => $this->config->item('ucp_admin'), "gm" => $this->config->item('ucp_gm')));
$this->template->view($this->template->loadPage("page.tpl", array("module" => "default", "headline" => lang("user_panel", "ucp"), "content" => $this->template->loadPage("ucp.tpl", $data))), "modules/ucp/css/ucp.css");
}
示例5: save
public function save($id = false)
{
if (!hasPermission("editAccounts")) {
die("UI.alert('You do not have permission to edit accounts')");
}
if (!$id || !is_numeric($id)) {
die;
}
$external_account_data[column("account", "expansion")] = $this->input->post("expansion");
$external_account_data[column("account", "email")] = $this->input->post("email");
if (hasPermission("editPermissions")) {
$this->acl_model->removePermissionsFromUser($id);
foreach ($_POST as $k => $v) {
if ($v !== '' && !in_array($k, array("vp", "dp", "nickname", "email", "group", "expansion", "password", "gm_level"))) {
$permissionParts = explode("-", $k);
// UserID, permissionName, moduleName
$this->acl_model->assignPermissionToUser($id, $permissionParts[1], $permissionParts[0], $v);
}
}
}
// Make sure to check if we got something filled in here.
if ($this->input->post("password")) {
$external_account_data[column("account", "password")] = $this->realms->getEmulator()->encrypt($this->user->getUsername($id), $this->input->post("password"));
}
$external_account_access_data[column("account_access", "gmlevel")] = $this->input->post("gm_level");
$internal_account_data["vp"] = $this->input->post("vp");
$internal_account_data["dp"] = $this->input->post("dp");
$internal_account_data["nickname"] = $this->input->post("nickname");
if (!$external_account_data[column("account", "email")] || !$internal_account_data["nickname"]) {
die("UI.alert('The fields can\\'t be empty')");
}
$this->accounts_model->save($id, $external_account_data, $external_account_access_data, $internal_account_data);
die('UI.alert("The account has been saved")');
}
示例6: authorize
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$hackedRoute = 'admin.page_category.update';
if (!is_null($this->segment(4))) {
$hackedRoute .= '#####' . $this->segment(3);
}
return hasPermission($hackedRoute);
}
示例7: __construct
public function __construct()
{
parent::__construct();
$this->_auth = new \tinyPHP\Classes\Libraries\Cookies();
if (!hasPermission('manage_roles')) {
redirect(BASE_URL . 'dashboard/');
}
}
示例8: getAddService
function getAddService()
{
include 'func/hasPerm.php';
if (hasPermission("addService")) {
if (isset($_POST['nazwa']) && ($_POST['nazwa'] == "" || $_POST['id_uslugi'] == "" || $_POST['serwer_id'] == "" || $_POST['opis'] == "" || $_POST['zdjecie'] == "" || $_POST['sms_tresc'] == "" || $_POST['sms_numer'] == "" || $_POST['sms_cena'] == "" || $_POST['api_konta'] == "" || $_POST['api_sms'] == "")) {
echo '
<div class="alert alert-danger" role="alert">
Zostawiłeś puste pola! Spróbuj ponownie!
</div>
';
echoServiceForm();
} else {
if (!isset($_POST['nazwa'])) {
echoServiceForm();
} else {
if (ctype_alnum($_POST['nazwa'])) {
include '../config/mysql.php';
$sql = "INSERT INTO services (server_id, nazwa, tresc, numer, koszt_sms, payment, acc_api, param, krotki_opis, img)\n\t\t\t\t\t\t\tVALUES ('" . $_POST['serwer_id'] . "', '" . $_POST['nazwa'] . "', '" . $_POST['sms_tresc'] . "', '" . $_POST['sms_numer'] . "', '" . $_POST['sms_cena'] . "', '" . $_POST['payment_id'] . "', '" . $_POST['api_konta'] . "', '" . $_POST['api_sms'] . "', '" . $_POST['opis'] . "', '" . $_POST['zdjecie'] . "')";
if ($conn->query($sql) === TRUE) {
echo '
<div class="alert alert-success" role="alert">
Usługa została dodana!<br>
Możesz teraz przystąpić do testowania!
</div>
';
echo '<meta http-equiv="refresh" content="3; url=index.php" />';
} else {
echo '
<div class="alert alert-danger" role="alert">
Wystąpił błąd podczas dodawania wpisu do bazy danych!
</div>
';
}
} else {
echo '
<div class="alert alert-danger" role="alert">
Podałeś nie poprawne dane!
</div>
';
echoServiceForm();
}
}
}
} else {
echo '
<div class="alert alert-danger" role="alert">
Nie masz uprawnień do dodawania usług!
</div>
';
}
}
示例9: getAddServer
function getAddServer()
{
include 'func/hasPerm.php';
if (hasPermission("addServer")) {
if (isset($_POST['nazwa']) && ($_POST['nazwa'] == "" || $_POST['serv_id'] == "" || $_POST['serv_ip'] == "" || $_POST['port_q'] == "" || $_POST['port_r'] == "" || $_POST['pass_r'] == "")) {
echo '
<div class="alert alert-danger" role="alert">
Zostawiłeś puste pola! Spróbuj ponownie!
</div>
';
echoForm();
} else {
if (!isset($_POST['nazwa'])) {
echoForm();
} else {
if (is_numeric($_POST['port_q']) && is_numeric($_POST['port_r']) && ctype_alnum($_POST['nazwa']) && ctype_alnum($_POST['serv_id']) && ctype_alnum($_POST['pass_r']) && ip2long($_POST['serv_ip']) !== false) {
include '../config/mysql.php';
$sql = "INSERT INTO servers (server_id, nazwa, ip, port_query, port_rcon, pasw_rcon)\n\t\t\t\t\t\t\tVALUES ('" . $_POST['serv_id'] . "', '" . $_POST['nazwa'] . "', '" . $_POST['serv_ip'] . "', '" . $_POST['port_q'] . "', '" . $_POST['port_r'] . "', '" . $_POST['pass_r'] . "')";
if ($conn->query($sql) === TRUE) {
echo '
<div class="alert alert-success" role="alert">
Nowy serwer został dodany!<br>
Możesz teraz przystąpić do dodawania usług.
</div>
';
echo '<meta http-equiv="refresh" content="3; url=index.php?page=serverList" />';
} else {
echo '
<div class="alert alert-danger" role="alert">
Wystąpił błąd podczas dodawania wpisu do bazy danych!
</div>
';
}
} else {
echo '
<div class="alert alert-danger" role="alert">
Porty muszą być cyframi, nazwa, ID serwera oraz hasło RCON nie może zawierać znaków specjalnych, lub IP jest nie poprawne.
</div>
';
}
}
}
} else {
echo '
<div class="alert alert-danger" role="alert">
Nie masz uprawnień do dodawania serwerów!
</div>
';
}
}
示例10: menuInit
/**
* init menus
*
* @param string $type
*/
public function menuInit($type)
{
Menu::make($type, function ($menu) use($type) {
$menus = $type . 'Menus';
foreach ($this->{$menus} as $action) {
$action::addMenu($menu);
}
})->filter(function ($item) {
if (is_null($item->data('permissions'))) {
return true;
}
return $this->user->is_super_admin || hasPermission($item->data('permissions')) ?: false;
});
}
示例11: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$route = Route::currentRouteName();
$method = $request->method();
$parameters = Route::current()->parameters();
$hackedRoute = routeHack($route, $parameters);
// if user destroy route
if ($method == 'GET' && in_array($route, $this->userDestroyRoutes) && !is_null(Request::route('users')) && Request::route('users')->id === Sentinel::getUser()->id) {
abort(403);
}
// dd($hackedRoute);
if ($method == 'GET' && !in_array($route, $this->exceptRoutes) && !Sentinel::getUser()->is_super_admin && ((!in_array($route, $this->userRoutes) || is_null(Request::route('users')) || Request::route('users')->id !== Sentinel::getUser()->id) && !hasPermission($hackedRoute))) {
abort(403);
}
return $next($request);
}
示例12: setRoutes
/**
* set routes
*
* @return void
*/
private function setRoutes()
{
foreach ($this->myModules as $module) {
$scModule = snake_case($module, '-');
$subModules = config("{$scModule}.permissions");
if (!is_null($subModules)) {
foreach ($subModules as $sub => $routes) {
$hasRoutes = array_filter(array_keys($routes['routes']), function ($item) {
return hasPermission($item);
});
if (count($hasRoutes) > 0) {
$this->routes[$scModule . '_' . $sub] = $routes;
}
}
}
}
}
示例13: hasPermissions
function hasPermissions($permissions, $conjuction = 'and')
{
if ($conjuction == 'and') {
foreach ($permissions as $permission) {
if (!hasPermission($permission)) {
return false;
}
}
return true;
} elseif ($conjuction == 'or') {
foreach ($permissions as $permission) {
if (hasPermission($permission)) {
return true;
}
}
return false;
} else {
throw new Exception("Illegal grammatical conjuction: {$conjuction}");
}
}
示例14: index
public function index()
{
if (isAdmin() || hasPermission('roles.content.CUD')) {
// echo "valid";
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$to_do_with_post = $_POST["todo"];
/*echo $to_do_with_post;*/
/*print_r($this->input->post());*/
if (isset($to_do_with_post)) {
if ($to_do_with_post == 'insert_roles') {
$this->_insertRoles($this->input->post());
}
}
} else {
$this->load->view('index.php');
}
} else {
echo "Please login first. Or you do not have the permission [access roles]";
}
}
示例15: boot
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
// The current user must be on the same crew as the user being destroyed, unless the current user is a Global Admin
$gate->define('destroy_user', function ($current_user, $user_to_destroy) {
return $current_user->crew_id === $user_to_destroy->crew_id;
})->before(function ($current_user, $ability) {
// Global Admin users will always be granted this permission
if ($current_user->isGlobalAdmin()) {
return true;
}
});
// The current user must be on the same crew as the Crew object passed in AND have the specified User->permission
// If $action is null, User->hasPermission($action) will return TRUE
$gate->define('performActionForCrew', function ($current_user, $target_crew, $action = null) {
return $current_user->crew_id === $target_crew->id && $current_user . hasPermission($action);
})->before(function ($current_user, $ability) {
// Global Admin users will always be granted this permission
if ($current_user->isGlobalAdmin()) {
return true;
}
});
// The current user must be a Crew Admin for the target Crew
$gate->define('actAsAdminForCrew', function ($current_user, $target_crew) {
// Allow $target_crew to be passed in as either a Crew object OR an Integer crew_id
// If $target_crew is NULL, return FALSE.... UNLESS the $current_user is a Global Admin
if (is_object($target_crew)) {
return $current_user->isAdminForCrew($target_crew->id);
} elseif (is_numeric($target_crew)) {
return $current_user->isAdminForCrew(intval($target_crew));
} else {
return false;
}
// An invalid data type was passed in for $target_crew (only integer or Crew Object are allowed)
})->before(function ($current_user, $ability) {
// Global Admin users will always be granted this permission
if ($current_user->isGlobalAdmin()) {
return true;
}
});
}