From ed4b0fc73dcd46ec3c97112663a30a7ecb1c391d Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Fri, 22 Jul 2022 00:06:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=A2=D0=B2=D0=B8=D0=B3=20=D0=B8=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BF=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B0?= =?UTF-8?q?=D0=BA=D1=83,=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=B0=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=B4=D1=80=D1=83=D0=B3=D0=B8=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=B0=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/login.php | 10 ++++++++++ admin/users.php | 2 ++ core/bootstrap.php | 5 ++++- core/lib/Core/App.class.php | 6 ++++-- templates/index.twig | 9 ++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/admin/login.php b/admin/login.php index 1d5a75e..f2a01d7 100644 --- a/admin/login.php +++ b/admin/login.php @@ -20,6 +20,7 @@ */ use Core\Models\User; + use Core\CoreException; require_once __DIR__ . '/inc/bootstrap.php'; @@ -44,6 +45,15 @@ } if ($auth === true) { + global $USER; + if (isset($_REQUEST['loginAs']) && !empty($_REQUEST['loginAs']) && $USER->isAdmin()) { + try { + User::logout(); + User::authorize($_REQUEST['loginAs']); + } catch (CoreException $e) { + die('Авторизация не удалась'); + } + } header('Location: index.php'); } else { ?> diff --git a/admin/users.php b/admin/users.php index 113d41c..7aaadf6 100644 --- a/admin/users.php +++ b/admin/users.php @@ -57,6 +57,7 @@ Был активен Создан Обновлен + @@ -88,6 +89,7 @@ + Войти CACHE_DIR, + $twig = new \Twig\Environment($loader, [ + 'debug' => true, + //'cache' => CACHE_DIR, ]); + $twig->addExtension(new \Twig\Extension\DebugExtension()); Cache::init(CACHE_DIR, USE_CACHE); diff --git a/core/lib/Core/App.class.php b/core/lib/Core/App.class.php index 16ecde8..4d39f82 100644 --- a/core/lib/Core/App.class.php +++ b/core/lib/Core/App.class.php @@ -25,14 +25,16 @@ { public static function index() { - global $twig; + global $twig, $USER; $navbarItems = [ ['name' => 'Главная', 'url' => '/', 'active' => true], ['name' => 'Админка', 'url' => '/admin', 'active' => false], ['name' => 'Командная PHP строка', 'url' => '/phpcmd.php', 'active' => false], ['name' => 'Тест', 'url' => '/test', 'active' => false], ]; - echo $twig->render('index.twig', ['navbarItems' => $navbarItems, 'name' => 'Roman Grinko']); + $userData = $USER ? $USER->getAllUserData() : ''; + $userRoles = $USER ? $USER->getRolesObject()->getFullRoles() : ''; + echo $twig->render('index.twig', ['navbarItems' => $navbarItems, 'name' => 'Roman Grinko', 'user' => $USER, 'userData' => $userData, 'userRoles' => $userRoles]); } public static function test(int $id = 1) diff --git a/templates/index.twig b/templates/index.twig index 705eb01..44cf19c 100644 --- a/templates/index.twig +++ b/templates/index.twig @@ -5,5 +5,12 @@ {% block title %}Главная страница{% endblock %} {% block content %} - тут текст главной страницы + тут текст главной страницы
+ {% if user %} + Hello, {{ user.name }}!
+ Your ID: {{ user.id }}
+
{{ dump(user) }}}}
+
{{ dump(userData) }}
+
{{ dump(userRoles) }}
+ {% endif %} {% endblock %} \ No newline at end of file