[+] базовый функционал авторизации и выхода из фронтовой части
This commit is contained in:
1 parent
e8be354a1f
commit
e52f73f8f8
9 files changed
+220
-13
No files matched your search
@@ -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]);
|
||||
}
|
||||
}
|
||||
@@ -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 = [];
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in new issue
Block a user