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 @@
= date('d.m.Y H:i:s', $elUser['last_active']); ?> |
= $elUser['date_created'] ? date('d.m.Y H:i:s', strtotime($elUser['date_created'])) : '-'; ?> |
= $elUser['date_updated'] ? date('d.m.Y H:i:s', strtotime($elUser['date_updated'])) : '-'; ?> |
+ Войти |
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