From cf7f7e959a92e602eca070ce1563578fc83ffdcb Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:50:26 +0300 Subject: [PATCH] Update pages --- app/Controllers/Api/Login.php | 90 +++++++++++++ app/Controllers/ApiController.php | 24 +--- app/Core/Routes.php | 2 + composer.json | 3 +- composer.lock | 76 ++++++++++- static/js/core.js | 98 ++++++++++++++ static/js/index.js | 213 ++++++++++++++++++++++++++++++ static/js/jquery-ui.js | 1 + static/js/jquery.js | 5 + views/components/LoadHead.php | 6 +- views/pages/Login.php | 99 ++++++++++++++ views/pages/Main.php | 14 +- 12 files changed, 598 insertions(+), 33 deletions(-) create mode 100644 app/Controllers/Api/Login.php create mode 100644 static/js/core.js create mode 100644 static/js/index.js create mode 100644 static/js/jquery-ui.js create mode 100644 static/js/jquery.js diff --git a/app/Controllers/Api/Login.php b/app/Controllers/Api/Login.php new file mode 100644 index 0000000..81a2741 --- /dev/null +++ b/app/Controllers/Api/Login.php @@ -0,0 +1,90 @@ + $username))) { + $email = DB::query('SELECT email FROM users WHERE email=:username OR username=:username', array(':username'=>$username))[0]['email']; + if (password_verify($password, DB::query('SELECT password FROM users WHERE email=:username', array(':username' => $email))[0]['password'])) { + $cstrong = True; + $token = GenerateRandomStr::gen_uuid(); + $user_id = DB::query('SELECT id FROM users WHERE email=:username', array(':username' => $email))[0]['id']; + + + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + $ip = $_SERVER['REMOTE_ADDR']; + } + + $parser = new UserAgentParser(); + + $ua = $parser->parse(); + $ua = $parser(); + + $servicekey = GenerateRandomStr::gen_uuid(); + $url = 'http://ip-api.com/json/'.$ip; + + $response = file_get_contents($url); + + $data = json_decode($response, true); + $loc = $data['country'].', '.$data['city']; + DB::query('INSERT INTO login_tokens VALUES (\'0\', :token, :user_id, :platform, :browser, :browserversion, 0, :ip, :servicekey, :loc)', array( + ':token' => $token, + ':user_id' => $user_id, + ':platform' => $ua->platform(), + ':browser' => $ua->browser(), + ':browserversion' => $ua->browserVersion(), + ':ip' => $ip, + ':servicekey' => $servicekey, + ':loc' => $loc + )); + + setcookie("BIRUXSESS", $token, time() + 50 * 50 * 54 * 72, '/', NULL, NULL, TRUE); + setcookie("BIRUXSERVICE", $servicekey, time() + 50 * 50 * 54 * 72, '/', NULL, NULL, TRUE); + setcookie("BIRUXSESS_", '1', time() + 50 * 50 * 54 * 72, '/', NULL, NULL, TRUE); + setcookie("BIRUXID", $user_id, time() + 50 * 50 * 54 * 72, '/', NULL, NULL, TRUE); + + echo Json::return ( + array( + 'errorcode' => '0', + 'error' => 0 + ) + ); + + + + } else { + echo Json::return ( + array( + 'errorcode' => '1', + 'error' => 1 + ) + ); + } + + } else { + echo Json::return ( + array( + 'errorcode' => '1', + 'error' => 1 + ) + ); + + } + } +} diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 6cf77fa..d0c6fbd 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -4,29 +4,13 @@ namespace App\Controllers; use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; - -class MainController +use \App\Controllers\Api\Login; +class ApiController { - public function __invoke() - { - - - } - public static function i() - { - - } - - public static function logout() - { - DB::query('DELETE FROM login_tokens WHERE servicekey=:userid', array(':userid'=>$_COOKIE['NGALLERYSERVICE'])); - setcookie('NGALLERYSERVICE', '', 1); - setcookie('NGALLERYSESS', '', 1); - setcookie('NGALLERYSESS_', '', 1); - setcookie('NGALLERYID', '', 1); - header('Location: /'); + public static function login() { + return new Login(); } } \ No newline at end of file diff --git a/app/Core/Routes.php b/app/Core/Routes.php index 7134f92..3e29f00 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -12,7 +12,9 @@ class Routes public static function init() { Router::get('/', 'MainController@i'); + Router::get('/login', 'LoginController@i'); Router::get('/photo/$id', 'PhotoController@i'); + Router::post('/api/login', 'ApiController@login'); diff --git a/composer.json b/composer.json index 1ae4515..ecf2126 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "require": { "aws/aws-sdk-php": "^3.315", "tracy/tracy": "^2.10", - "symfony/yaml": "^7.1" + "symfony/yaml": "^7.1", + "donatj/phpuseragentparser": "^1.8" } } diff --git a/composer.lock b/composer.lock index 03b4ec2..ce9364c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4cb3046ee61db32e4866c8f8ba6c0f99", + "content-hash": "73b4865b189367ec43d243dbb63808e2", "packages": [ { "name": "aws/aws-crt-php", @@ -155,6 +155,80 @@ }, "time": "2024-07-03T18:12:51+00:00" }, + { + "name": "donatj/phpuseragentparser", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/donatj/PhpUserAgent.git", + "reference": "b8c16fd6e963651c6d86f66cb782ce599d62418e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/donatj/PhpUserAgent/zipball/b8c16fd6e963651c6d86f66cb782ce599d62418e", + "reference": "b8c16fd6e963651c6d86f66cb782ce599d62418e", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "camspiers/json-pretty": "~1.0", + "donatj/drop": "*", + "ext-json": "*", + "phpunit/phpunit": "~4.8|~9" + }, + "type": "library", + "autoload": { + "files": [ + "src/UserAgentParser.php" + ], + "psr-4": { + "donatj\\UserAgent\\": "src/UserAgent" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jesse G. Donat", + "email": "donatj@gmail.com", + "homepage": "https://donatstudios.com", + "role": "Developer" + } + ], + "description": "Lightning fast, minimalist PHP UserAgent string parser.", + "homepage": "https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT", + "keywords": [ + "browser", + "browser detection", + "parser", + "user agent", + "useragent" + ], + "support": { + "issues": "https://github.com/donatj/PhpUserAgent/issues", + "source": "https://github.com/donatj/PhpUserAgent/tree/v1.8.0" + }, + "funding": [ + { + "url": "https://www.paypal.me/donatj/15", + "type": "custom" + }, + { + "url": "https://github.com/donatj", + "type": "github" + }, + { + "url": "https://ko-fi.com/donatj", + "type": "ko_fi" + } + ], + "time": "2023-10-27T05:22:44+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "7.8.1", diff --git a/static/js/core.js b/static/js/core.js new file mode 100644 index 0000000..fa11c09 --- /dev/null +++ b/static/js/core.js @@ -0,0 +1,98 @@ +var _text = {}; + +function _getID(t) +{ + return document.getElementById(t); +} + +function trim(t) +{ + return t.replace(/^\s+/, '').replace(/\s+$/, ''); +} + +function addTexts(txt) +{ + for (var key in txt) _text[key] = txt[key]; +} + +function switchClass(objNode, strCurrClass, strNewClass) +{ + if (matchClass(objNode, strNewClass)) + replaceClass(objNode, strCurrClass, strNewClass); + else replaceClass(objNode, strNewClass, strCurrClass); +} + +function removeClass(objNode, strCurrClass) +{ + replaceClass(objNode, '', strCurrClass); +} + +function addClass(objNode, strNewClass) +{ + replaceClass(objNode, strNewClass, ''); +} + +function replaceClass(objNode, strNewClass, strCurrClass) +{ + var strOldClass = strNewClass; + if (strCurrClass && strCurrClass.length) + { + strCurrClass = strCurrClass.replace('/\s+(\S)/g', '|$1'); + if (strOldClass.length) strOldClass += '|'; + strOldClass += strCurrClass; + } + objNode.className = objNode.className.replace(new RegExp('(^|\\s+)(' + strOldClass + ')($|\\s+)', 'g'), '$1'); + objNode.className += ((objNode.className.length)? ' ' : '') + strNewClass; +} + +function matchClass(objNode, strCurrClass) +{ + return (objNode && objNode.className.length && objNode.className.match(new RegExp('(^|\\s+)(' + strCurrClass + ')($|\\s+)'))); +} + +function showId(id) +{ + _getID(id).style.display = 'block'; +} + +function hideId(id) +{ + _getID(id).style.display = 'none'; +} + + +$(document).ready(function() +{ + $(this).on('keydown', function(e) + { + if ($(e.target).is('input, textarea')) return; + + if (e.ctrlKey) + { + var link; + + switch (e.which) + { + case 0x24: window.location = '/'; return; + case 0x25: link = 'PrevLink'; break; + case 0x27: link = 'NextLink'; break; + case 0x26: link = 'UpLink'; break; + case 0x28: link = 'DownLink'; break; + } + + if (link) + { + var a = $('#' + link); + if (a.length) window.location = a.attr('href') + } + } + }); + + $('a.self-close').on('click', function() + { + window.open(this.href); + return false; + }); + + $('input, select, textarea', $('.form-field')).on('focus blur', function() { $(this).closest('.form-field').toggleClass('active').prev('.form-label').toggleClass('active'); }) +}); \ No newline at end of file diff --git a/static/js/index.js b/static/js/index.js new file mode 100644 index 0000000..3146a52 --- /dev/null +++ b/static/js/index.js @@ -0,0 +1,213 @@ +ar1 = new Image(); +ar1.src = '/img/ar1.gif'; + + +$(document).ready(function() +{ + $('.ix-country > a[href="#"]').on('click', function(e) + { + var block = $(this).parent().next('div'); + if (block.is(':hidden')) + { + block.slideDown(); + $('.ix-arrow', this).addClass('ix-arrow-expanded'); + } + else + { + block.slideUp(); + $('.ix-arrow', this).removeClass('ix-arrow-expanded'); + } + + return false; + }); + + + $(window).on('load resize', function() + { + var list = $('#idx-regions-list'); + var h = list.closest('table').height() - list.position().top + 40; + list.css('height', h + 'px'); + }); + + + $('#loadmore').on('click', LoadRecentPhotos).click(); + $('#newrand' ).on('click', LoadRandomPhotos).click(); + + updateInterval = setInterval(LoadPubPhotos, 60000); + + + //$('#cname').citySelector('cid', { defaultLabel: _text['IX_ANY'] }); + + + $('#type').on('change', function() { $('#type').attr('class', $('#type option:selected').attr('class')); }).change(); + $('#num').on('change keyup', function() { $('#qsearch').prop('disabled', $('#num').val().trim() == ''); }).on('keypress', function(event) { if (event.keyCode == 13) { searchVehicles(); return false; } }).change(); + $('#searchbtn').on('click', searchVehicles); + + + /*$('#qcity').citySelector(null, { + selectCallback: function(item) { window.open('/city/' + item.value + '/'); }, + clearField: true + });*/ + + + $(document).on('click', function(e) + { + var target = $(e.target); + if (target.closest('#cars_list').length > 0 || + target.closest('#idx-column-menu').length > 0 || + target.is('#mobile-menu') || + target.is('button')) return; + + $('#cars_list').hide().html(''); + + var menu = $('div#idx-column-menu'); + if (menu.is(':visible')) + { + menu.hide(); + $('#backgr').hide(); + } + + e.stopPropagation(); + }); + + + $('#loginbtn').on('click', function() + { + var username = $('#username').val().trim(); + var password = $('#password').val().trim(); + + if (username != '' && username != '') + { + $('#loginbtn').prop('disabled', true).val(_text['IX_LOGGING']); + + $.post('/api.php?action=check-login', { username: username, password: password, remember: $('#remember').is('checked') }, function(r) + { + if (r == 0) + $('#loginform').submit(); + else window.location.reload(); + }) + .fail(function(jx) { if (jx.responseText != '') alert(jx.responseText); }); + } + }); + + + $('#mobile-menu').on('click', function() + { + $('#idx-column-menu, #backgr').toggle(); + return false; + }); + + + $('.ix-plus, .ix-minus').on('click', function() + { + $(this).toggleClass('ix-plus ix-minus'); + + var block = $(this).closest('.ix-region'); + $('.ix-hideable-citylist, .ix-hideable-cname', block).toggle(); + + return false; + }); +}); + + +function searchVehicles() +{ + $('#cars_list').html('').show(); + $.get('/api.php', { action: 'index-qsearch', cid: $('#cid').val(), type: $('#type').val(), num: $('#num').val() }, function (r) { $('#cars_list').html(r); }); + return false; +} + + + +function AddPhotoToBlock(block, arr, prepend) +{ + block[prepend ? 'prepend' : 'append']('
+ Вход на сайт+
+
+
+
+
+
+ + + + |
+
Главная Форум Правила Редколлегия + Мобильная версия Тёмная тема + © Администрация ТрансФото и авторы материалов, 2002—2024
+ Использование фотографий и иных материалов, опубликованных на сайте, допускается только с разрешения их авторов.
+
+
+
+ |
+