отладка в Твиг и вывод информации по польаку, также авторизация под другими пользаками

This commit is contained in:
rsgrinko committed 2022-07-22 00:06:29 +03:00
1 parent 8188bb722a
commit ed4b0fc73d
5 files changed
+28 -4

No files matched your search

+10
View File
@@ -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 {
?>
+2
View File
@@ -57,6 +57,7 @@
<th>Был активен</th>
<th>Создан</th>
<th>Обновлен</th>
<th></th>
</tr>
</thead>
<tbody>
@@ -88,6 +89,7 @@
<td><?= date('d.m.Y H:i:s', $elUser['last_active']); ?></td>
<td><?= $elUser['date_created'] ? date('d.m.Y H:i:s', strtotime($elUser['date_created'])) : '-'; ?></td>
<td><?= $elUser['date_updated'] ? date('d.m.Y H:i:s', strtotime($elUser['date_updated'])) : '-'; ?></td>
<td><a class="btn btn-primary" href="login.php?loginAs=<?= $elUser['id']; ?>">Войти</a></td>
</tr>
<?php
}
+4 -1
View File
@@ -93,8 +93,11 @@
* Инициализация шаблонизатора
*/
$loader = new \Twig\Loader\FilesystemLoader(PATH_TO_TEMPLATES);
$twig = new \Twig\Environment($loader, [//'cache' => CACHE_DIR,
$twig = new \Twig\Environment($loader, [
'debug' => true,
//'cache' => CACHE_DIR,
]);
$twig->addExtension(new \Twig\Extension\DebugExtension());
Cache::init(CACHE_DIR, USE_CACHE);
+4 -2
View File
@@ -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)
+8 -1
View File
@@ -5,5 +5,12 @@
{% block title %}Главная страница{% endblock %}
{% block content %}
тут текст главной страницы
тут текст главной страницы<br>
{% if user %}
Hello, {{ user.name }}!<br>
Your ID: {{ user.id }}<br>
<pre>{{ dump(user) }}}}</pre>
<pre>{{ dump(userData) }}</pre>
<pre>{{ dump(userRoles) }}</pre>
{% endif %}
{% endblock %}