[+] базовый функционал авторизации и выхода из фронтовой части

This commit is contained in:
rsgrinko committed 2023-07-24 20:27:46 +03:00
1 parent e8be354a1f
commit e52f73f8f8
9 files changed
+220 -13

No files matched your search

+53 -6
View File
@@ -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;
}
+42 -1
View File
@@ -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]);
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
/**
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
* 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 = [];
}
}
+3
View File
@@ -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));
}
}
+6
View File
@@ -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 () {
+5 -1
View File
@@ -34,7 +34,11 @@
<div class="messageBox">
{% for message in messages %}
<div class="message {% if message.user_from == userId %}fromMe{% else %}fromCompanion{% endif %}">{{ message.text }}</div>
<div class="message {% if message.user_from == userId %}fromMe{% else %}fromCompanion{% endif %}">
<div class="name">{{ message.user_from_data.name }}</div>
<div class="text">{{ message.text }}</div>
<div class="date">{{ message.date }}</div>
</div>
{% endfor %}
</div>
+18 -5
View File
@@ -3,6 +3,7 @@
<head>
<title>{% block title %}Delta Framework{% endblock %}</title>
<link href="/assets/css/style.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
@@ -14,13 +15,25 @@
<div class="header">
<div class="mainMenu">
<div class="menuItem"><a href="/">Главная</a></div>
<div class="menuItem {% if currentPage == 'index' %}active{% endif %}"><a href="/">Главная</a></div>
<div class="menuItem"><a href="/admin/">Админка</a></div>
<div class="menuItem"><a href="/">Link</a></div>
<div class="menuItem"><a href="/info">Информация о сборке</a></div>
<div class="menuItem"><a href="/test">Тестовая</a></div>
{% if isAuthorized %}
<div class="menuItem {% if currentPage == 'dialogs' %}active{% endif %}"><a href="/dialogs">Диалоги</a></div>
{% endif %}
<div class="menuItem {% if currentPage == 'users' %}active{% endif %}"><a href="/users">Список пользователей</a></div>
<div class="menuItem {% if currentPage == 'info' %}active{% endif %}"><a href="/info">Информация о сборке</a></div>
<div class="menuItem {% if currentPage == 'test' %}active{% endif %}"><a href="/test">Тестовая</a></div>
<div class="userInfo">
{% if isAuthorized %}
{{ userData.name }} [<a href="/logout">Выход</a>]
{% else %}
Гость [<a href="/login">Войти</a>]
{% endif %}
</div>
</div>
</div>
<div class="content">
<div class="breadcrumbs"><a href="/">Главная</a> &raquo; Раздел &raquo; Тестовая</div>
@@ -28,7 +41,7 @@
</div>
<div class="footer">
<a href="https://github.com/rsgrinko/delta_framework" target="_blank">DeltaFramework</a> by Roman S Grinko, {{ currentYear }}
<a href="https://github.com/rsgrinko/delta_framework" target="_blank">DeltaFramework</a> by <a href="https://it-stories.ru/about" target="_blank">Roman S Grinko</a>, {{ currentYear }} | Generation time: {{ executionTime }}
</div>
</div>
</body>
+15
View File
@@ -0,0 +1,15 @@
{% extends 'layout.twig' %}
{% block title %}Авторизация{% endblock %}
{% block main %}
<h1>Авторизация</h1>
{% if failed %}
<div class="alert alert-error">Ошибка авторизации</div>
{% endif %}
<p>
<form action="/login/authorize" method="POST">
<input class="input" type="text" name="login" placeholder="Введите логин">
<input class="input" type="password" name="password" placeholder="Введите пароль">
<button class="button w100" type="submit">Войти</button>
</form>
</p>
{% endblock %}
+8
View File
@@ -0,0 +1,8 @@
{% extends 'layout.twig' %}
{% block title %}Список пользователей{% endblock %}
{% block main %}
<h1>Список пользователей</h1>
<p>This is sample text!</p>
{% endblock %}