From e52f73f8f851eb54d7266e0e13df790ab1105c91 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Mon, 24 Jul 2023 20:27:46 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=20=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=87=D0=B0=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/css/style.css | 59 ++++++++++++++++++-- core/lib/Core/App.class.php | 43 ++++++++++++++- core/lib/Core/Helpers/Registry.class.php | 70 ++++++++++++++++++++++++ core/lib/Core/Models/Router.class.php | 3 + core/routes.php | 6 ++ templates/dialog.twig | 6 +- templates/layout.twig | 23 ++++++-- templates/login.twig | 15 +++++ templates/users.twig | 8 +++ 9 files changed, 220 insertions(+), 13 deletions(-) create mode 100644 core/lib/Core/Helpers/Registry.class.php create mode 100644 templates/login.twig create mode 100644 templates/users.twig diff --git a/assets/css/style.css b/assets/css/style.css index 1636fce..30c1087 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -3,7 +3,7 @@ body { } .main { - width: 1100px; + max-width: 1100px; margin: 0 auto; margin-top: 30px; } @@ -37,7 +37,11 @@ body { background: #0085c7; } -.main .header .mainMenu .menuItem:first-child:hover { +.main .header .mainMenu .menuItem.active { + background: #0085c7; +} + +.main .header .mainMenu .menuItem:first-child:hover, .main .header .mainMenu .menuItem.active:first-child { border-radius: 10px 0px 0px 0px; } @@ -105,28 +109,32 @@ body { color: #00abff; } -.table{ +.table { border: 1px solid #eee; table-layout: fixed; width: 100%; margin-bottom: 20px; border-collapse: collapse; } + .table th { font-weight: bold; padding: 5px; background: #efefef; border: 1px solid #dddddd; } -.table td{ + +.table td { padding: 5px 10px; border: 1px solid #eee; text-align: left; } -.table tbody tr:nth-child(odd){ + +.table tbody tr:nth-child(odd) { background: #fff; } -.table tbody tr:nth-child(even){ + +.table tbody tr:nth-child(even) { background: #F7F7F7; } @@ -140,9 +148,18 @@ body { margin-bottom: 10px; } +.main .input { + width: 100%; + margin-bottom: 5px; + margin-top: 5px; + border: 1px solid #00abff; + padding: 10px; +} + .main .w100 { width: 100%; } + .main .button { background: #00abff; color: white; @@ -167,6 +184,8 @@ body { background: #eee; border-radius: 3px; margin-bottom: 10px; + display: flex; + flex-direction: column; } .main .messageBox .message.fromMe { @@ -198,3 +217,31 @@ body { transform: rotate(180deg); } +.main .messageBox .message .name { + font-weight: bold; + position: absolute; + top: 5px; +} + +.main .messageBox .message .text { + margin-top: 10px; + margin-bottom: 10px; +} + +.main .messageBox .message .date { + font-size: 0.7em; + align-self: end; +} + +.main .header .mainMenu .userInfo { + margin-left: auto; + background: #006fa7; + padding: 10px; + color: white; + border-radius: 10px 10px 0px 10px; +} + +.main .header .mainMenu a { + color: white; + text-decoration: none; +} \ No newline at end of file diff --git a/core/lib/Core/App.class.php b/core/lib/Core/App.class.php index d271142..d6023c9 100644 --- a/core/lib/Core/App.class.php +++ b/core/lib/Core/App.class.php @@ -21,6 +21,7 @@ namespace Core; + use Core\Helpers\Registry; use Core\Helpers\SystemFunctions; use Core\Models\{Posts, User}; @@ -35,10 +36,21 @@ { global $USER; + $finish_time = microtime(true); + $delta = round($finish_time - START_TIME, 3); + if ($delta < 0.001) { + $delta = 0.001; + } + + $currentPage = explode('::', Registry::get('currentPage'))[1]; + return [ + 'currentPage' => $currentPage, + 'executionTime' => $delta . ' cek.', 'isAuthorized' => User::isAuthorized(), 'isAdmin' => User::isAuthorized() && $USER->isAdmin(), - 'currentYear' => date('Y'), + 'userData' => User::isAuthorized() ? $USER->getAllUserData(true) : [], + 'currentYear' => date('Y'), ]; } @@ -127,6 +139,10 @@ header('Location: /dialog/' . (int)$_REQUEST['dialogId']); } + public static function users() + { + self::render('users.twig'); + } /** *Тестовая @@ -137,4 +153,29 @@ { self::render('test.twig'); } + + public static function logout() + { + User::logout(); + header('Location: /'); + } + + public static function loginAuthorize() + { + if (User::securityAuthorize($_REQUEST['login'], $_REQUEST['password'], false)) { + header('Location: /'); + } else { + header('Location: /login/failed'); + } + } + + public static function login() + { + self::render('login.twig', ['failed' => false]); + } + + public static function loginFailed() + { + self::render('login.twig', ['failed' => true]); + } } \ No newline at end of file diff --git a/core/lib/Core/Helpers/Registry.class.php b/core/lib/Core/Helpers/Registry.class.php new file mode 100644 index 0000000..7314a36 --- /dev/null +++ b/core/lib/Core/Helpers/Registry.class.php @@ -0,0 +1,70 @@ + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + namespace Core\Helpers; + + class Registry + { + /** @var array $_storage Массив данных */ + private static array $_storage = []; + + /** + * Установка значения + * + * @param string $key Ключ + * @param mixed $value Значение + */ + public static function set(string $key, $value): void + { + self::$_storage[$key] = $value; + } + + /** + * Получение значения + * + * @param string $key Ключ + * @param mixed $default Значение по умолчанию + * + * @return mixed|null + */ + public static function get(string $key, $default = null) + { + return (isset(self::$_storage[$key])) ? self::$_storage[$key] : $default; + } + + /** + * Удаление + * + * @param string $key Ключ + */ + public static function remove(string $key): void + { + unset(self::$_storage[$key]); + } + + /** + * Полная очистка + */ + public static function flush(): void + { + self::$_storage = []; + } + } \ No newline at end of file diff --git a/core/lib/Core/Models/Router.class.php b/core/lib/Core/Models/Router.class.php index 42d9526..11608fe 100644 --- a/core/lib/Core/Models/Router.class.php +++ b/core/lib/Core/Models/Router.class.php @@ -21,6 +21,8 @@ namespace Core\Models; + use Core\Helpers\Registry; + class Router { @@ -68,6 +70,7 @@ if (preg_match($pattern, $_SERVER['REQUEST_URI'], $params)) // сравнение идет через регулярное выражение { array_shift($params); + Registry::set('currentPage', $callback); return call_user_func_array($callback, array_values($params)); } } diff --git a/core/routes.php b/core/routes.php index 06f3f75..1b08b3c 100644 --- a/core/routes.php +++ b/core/routes.php @@ -26,10 +26,16 @@ Router::route('/test', '\Core\App::test'); Router::route('/info', '\Core\App::info'); + Router::route('/login', '\Core\App::login'); + Router::route('/login/authorize', '\Core\App::loginAuthorize'); + Router::route('/login/failed', '\Core\App::loginFailed'); + Router::route('/logout', '\Core\App::logout'); + Router::route('/dialogs', '\Core\App::dialogs'); Router::route('/dialog/(\d+)', '\Core\App::dialog'); + Router::route('/users', '\Core\App::users'); Router::route('/users/(\d+)/sendMessage', '\Core\App::sendMessage'); Router::route('/404', function () { diff --git a/templates/dialog.twig b/templates/dialog.twig index e65ea75..e7c5d55 100644 --- a/templates/dialog.twig +++ b/templates/dialog.twig @@ -34,7 +34,11 @@
{% for message in messages %} -
{{ message.text }}
+
+
{{ message.user_from_data.name }}
+
{{ message.text }}
+
{{ message.date }}
+
{% endfor %}
diff --git a/templates/layout.twig b/templates/layout.twig index 496be3b..b1365ea 100644 --- a/templates/layout.twig +++ b/templates/layout.twig @@ -3,6 +3,7 @@ {% block title %}Delta Framework{% endblock %} + @@ -14,13 +15,25 @@
+
@@ -28,7 +41,7 @@
diff --git a/templates/login.twig b/templates/login.twig new file mode 100644 index 0000000..4dad686 --- /dev/null +++ b/templates/login.twig @@ -0,0 +1,15 @@ +{% extends 'layout.twig' %} +{% block title %}Авторизация{% endblock %} +{% block main %} +

Авторизация

+ {% if failed %} +
Ошибка авторизации
+ {% endif %} +

+

+ + + +
+

+{% endblock %} \ No newline at end of file diff --git a/templates/users.twig b/templates/users.twig new file mode 100644 index 0000000..173a2ba --- /dev/null +++ b/templates/users.twig @@ -0,0 +1,8 @@ +{% extends 'layout.twig' %} + +{% block title %}Список пользователей{% endblock %} + +{% block main %} +

Список пользователей

+

This is sample text!

+{% endblock %} \ No newline at end of file