From 8cb0b860eaa0d1f812c683c350c1ae17ba43d67c Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Sat, 28 Oct 2023 16:12:27 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3=D1=80=D0=B0=D0=BC=20(?= =?UTF-8?q?=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/inc/header.php | 7 +- admin/login.php | 125 ++++++++++++++---- core/config.php | 9 +- .../Core/Helpers/SystemFunctions.class.php | 33 +++++ core/lib/Core/Models/UserMeta.class.php | 15 +++ 5 files changed, 157 insertions(+), 32 deletions(-) diff --git a/admin/inc/header.php b/admin/inc/header.php index 95f18f5..ee614f9 100644 --- a/admin/inc/header.php +++ b/admin/inc/header.php @@ -42,7 +42,7 @@ - Delta - CPanel + Delta - CPanel<?= isset($pageTitle) ? ' | ' . $pageTitle : '' ?> @@ -59,11 +59,14 @@ width: 100%; height: 70px; } + .telegramAuthButtonBox { + margin-top: 20px; + float: right; + } -
diff --git a/admin/login.php b/admin/login.php index c2e9b33..73066f6 100644 --- a/admin/login.php +++ b/admin/login.php @@ -20,35 +20,82 @@ */ use Core\Helpers\Captcha; - use Core\Models\User; + use Core\Helpers\SystemFunctions; + use Core\SystemConfig; + use Core\Models\{User, UserMeta}; use Core\CoreException; require_once __DIR__ . '/inc/bootstrap.php'; - $captchaCorrect = true; - if (USE_CAPTCHA) { - $captchaCorrect = isset($_REQUEST['captchaCode']) && Captcha::isValidCaptcha($_REQUEST['captchaCode']); + // Определяем тип авторизации + $authType = isset($_REQUEST['authType']) && !empty($_REQUEST['authType']) ? $_REQUEST['authType'] : 'default'; + + + /** + * array(7) { + ["id"]=> string(7) "1831337" + ["first_name"]=> string(18) "Александр" + ["last_name"]=> string(16) "Менщиков" + ["username"]=> string(5) "n0str" + ["photo_url"]=> string(36) "https://t.me/i/userpic/100/n0str.jpg" + ["auth_date"]=> string(10) "1518168109" + ["hash"]=> string(64) "abba<..>1345" + } + */ + switch ($authType) { + case 'telegram': + $data = [ + 'id' => $_REQUEST['id'], + 'first_name' => $_REQUEST['first_name'], + 'last_name' => $_REQUEST['last_name'], + 'username' => $_REQUEST['username'], + 'photo_url' => $_REQUEST['photo_url'], + 'auth_date' => $_REQUEST['auth_date'], + 'hash' => $_REQUEST['hash'], + ]; + $isCorrectTelegramAuth = SystemFunctions::checkTelegramAuthorization($data); + if ($isCorrectTelegramAuth) { + $res = UserMeta::getListByParams(['name' => 'telegramId', 'value' => $data['id']]); + if (!empty($res)) { + $userId = array_shift($res)['user_id']; + User::authorize($userId); + header('Location: index.php'); + die(); + } + } + $auth = false; + $err_mess = true; + break; + case 'default': + $captchaCorrect = true; + if (USE_CAPTCHA) { + $captchaCorrect = isset($_REQUEST['captchaCode']) && Captcha::isValidCaptcha($_REQUEST['captchaCode']); + } + + if (User::isAuthorized()) { + $auth = true; + } else { + $auth = false; + if ($captchaCorrect && !empty($_REQUEST['login'] && !empty($_REQUEST['pass']))) { + if (User::securityAuthorize( + $_REQUEST['login'], + $_REQUEST['pass'], + isset($_REQUEST['remember']) && $_REQUEST['remember'] === 'on' + )) { + $auth = true; + } + } + } + if ($auth === false && isset($_REQUEST['login']) && $_REQUEST['login'] !== '') { + $err_mess = true; + } else { + $err_mess = false; + } + break; + } - if (User::isAuthorized()) { - $auth = true; - } else { - $auth = false; - if ($captchaCorrect && !empty($_REQUEST['login'] && !empty($_REQUEST['pass']))) { - if (User::securityAuthorize( - $_REQUEST['login'], - $_REQUEST['pass'], - isset($_REQUEST['remember']) && $_REQUEST['remember'] === 'on' - )) { - $auth = true; - } - } - } - if ($auth === false && isset($_REQUEST['login']) && $_REQUEST['login'] !== '') { - $err_mess = true; - } else { - $err_mess = false; - } + if ($auth === true) { global $USER; @@ -56,6 +103,7 @@ try { User::logout(); User::authorize($_REQUEST['loginAs']); + die(); } catch (CoreException $e) { die('Авторизация не удалась'); } @@ -70,23 +118,23 @@ - Delta Framework - Авторизация - - + - -
-