From 677384c15350c6b6b56ba962c4f34eb5ec4110f2 Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Mon, 3 Nov 2025 15:09:59 +0300 Subject: [PATCH] starting farting --- .gitmodules | 3 + composer.json | 5 +- damper.mjs | 1 + install.sh | 13 +- zharko/site/system/controllers/account.php | 120 ++++++ zharko/site/system/controllers/core.php | 15 +- zharko/site/system/controllers/index.php | 1 - zharko/site/system/models/account.php | 74 +++- .../system/models/enumerations/language.php | 62 --- .../system/models/enumerations/session.php | 19 + .../system/models/middlewares/account.php | 43 ++ .../system/models/middlewares/session.php | 55 +++ zharko/site/system/models/session.php | 169 ++++++++ zharko/site/system/public/index.php | 12 +- zharko/site/system/public/js/core.js | 404 ++++++++++++++++++ zharko/site/system/public/js/libraries/md5.js | 1 + .../site/system/public/js/modules/damper.mjs | 1 + .../site/system/public/js/modules/loader.mjs | 280 ++++++++++++ .../public/js/pages/account/registration.js | 144 +++++++ zharko/site/system/views/templater.php | 4 +- .../site/system/views/themes/default/js.html | 14 +- .../default/pages/account/registration.html | 24 ++ 22 files changed, 1369 insertions(+), 95 deletions(-) create mode 100644 .gitmodules create mode 160000 damper.mjs create mode 100755 zharko/site/system/controllers/account.php delete mode 100755 zharko/site/system/models/enumerations/language.php create mode 100644 zharko/site/system/models/enumerations/session.php create mode 100755 zharko/site/system/models/middlewares/account.php create mode 100755 zharko/site/system/models/middlewares/session.php create mode 100755 zharko/site/system/models/session.php create mode 100644 zharko/site/system/public/js/core.js create mode 100644 zharko/site/system/public/js/libraries/md5.js create mode 120000 zharko/site/system/public/js/modules/damper.mjs create mode 100644 zharko/site/system/public/js/modules/loader.mjs create mode 100644 zharko/site/system/public/js/pages/account/registration.js create mode 100644 zharko/site/system/views/themes/default/pages/account/registration.html diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4cb7545 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "damper.mjs"] + path = damper.mjs + url = https://git.svoboda.works/mirzaev/damper.mjs diff --git a/composer.json b/composer.json index f4d052a..0c90925 100755 --- a/composer.json +++ b/composer.json @@ -27,7 +27,10 @@ "mirzaev/baza": "^3.3", "twig/twig": "^3.2", "twig/extra-bundle": "^3.7", - "twig/intl-extra": "^3.10" + "twig/intl-extra": "^3.10", + "mirzaev/languages": "^1.0", + "mirzaev/currencies": "^1.0", + "svoboda/time": "^1.0" }, "autoload": { "psr-4": { diff --git a/damper.mjs b/damper.mjs new file mode 160000 index 0000000..81d208b --- /dev/null +++ b/damper.mjs @@ -0,0 +1 @@ +Subproject commit 81d208b96470e6068e735f38ccfc0f941079c3a5 diff --git a/install.sh b/install.sh index debfdda..3a0f0a2 100755 --- a/install.sh +++ b/install.sh @@ -1,10 +1,5 @@ -#!/bin/bash - -if [ -d author/project ]; then - mv author/project author/site -fi - -if [ -d author ]; then - mv author zharko -fi +#!/bin/fish +if not test -L zharko/site/system/public/js/modules/damper.mjs + ln -s ../../../../../../damper.mjs/damper.mjs zharko/site/system/public/js/modules/damper.mjs; +end diff --git a/zharko/site/system/controllers/account.php b/zharko/site/system/controllers/account.php new file mode 100755 index 0000000..c7072ed --- /dev/null +++ b/zharko/site/system/controllers/account.php @@ -0,0 +1,120 @@ + + */ +final class account extends core +{ + /** + * Errors + * + * @var array $errors Registry of errors + */ + protected array $errors = [ + 'system' => [], + 'account' => [] + ]; + + /** + * Registration page + * + * @param string|null $mail Mail + * @param string|null $password Password + * + * @return null + */ + public function registration( + ?string $mail = null, + ?string $password = null + ): null { + if ($this->request->method === method::put) { + // PUT (creating the account) + + if (str_contains($this->request->headers['accept'] ?? '', content::json->value)) { + // Request for JSON response + + // Filtering the mail value + preg_match('/([^@\r\n]+)@([^@\r\n\.]+)\.([^@\r\n\.]+)/u', 'vova@mail.ru', $matches); + $mail = $matches[1] . '@' . $matches[2] . '.' . $matches[3]; + unset($matches); + + // Filtering the password value + preg_match_all('/[^a-fA-F0-9]+/Uu', $password, $password_restricted); + + if (empty($mail)) { + // Mail is empty + + } else if (empty($password)) { + // Password is empty + + } else if (!empty($password_restricted)) { + // Pasword has restricted symbols + + } else { + // All parameters validated + + // Creating the account + $this->model->write(mail: $mail, password: $password, errors: $this->errors['account']); + + // Exit (success) + return null; + } + + // Exit (fail) + return null; + } + } else if ($this->request->method === method::get) { + // GET (sending the HTML-document for registration) + + if (str_contains($this->request->headers['accept'] ?? '', content::html->value)) { + // Request for HTML response + + // Render page + $page = $this->view->render('pages/account/registration.html'); + + // Sending response + $this->response + ->start() + ->clean() + ->sse() + ->write($page) + ->validate($this->request) + ?->body() + ->end(); + + // Deinitializing rendered page + unset($page); + + // Exit (success) + return null; + } + } + + // Exit (fail) + return null; + } +} diff --git a/zharko/site/system/controllers/core.php b/zharko/site/system/controllers/core.php index 00647eb..7aeafb6 100755 --- a/zharko/site/system/controllers/core.php +++ b/zharko/site/system/controllers/core.php @@ -7,8 +7,8 @@ namespace zharko\site\controllers; // Files of the project use zharko\site\views\templater, zharko\site\models\core as models, - zharko\site\models\account, - zharko\site\models\enumerations\language; + zharko\site\models\session, + zharko\site\models\account; // Framework for PHP use mirzaev\minimal\core as minimal, @@ -16,6 +16,9 @@ use mirzaev\minimal\core as minimal, mirzaev\minimal\http\response, mirzaev\minimal\http\enumerations\status; +// Library for languages support +use mirzaev\languages\language; + /** * Controllers core * @@ -30,10 +33,16 @@ use mirzaev\minimal\core as minimal, * * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License * @author Arsen Mirzaev Tatyano-Muradovich - * @author zharko */ class core extends controller { + /** + * Session + * + * @var session $session Session + */ + protected session $session; + /** * Account * diff --git a/zharko/site/system/controllers/index.php b/zharko/site/system/controllers/index.php index 5d2afa7..f13b1e3 100755 --- a/zharko/site/system/controllers/index.php +++ b/zharko/site/system/controllers/index.php @@ -22,7 +22,6 @@ use mirzaev\minimal\http\enumerations\content, * * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License * @author Arsen Mirzaev Tatyano-Muradovich - * @author zharko */ final class index extends core { diff --git a/zharko/site/system/models/account.php b/zharko/site/system/models/account.php index 6d3b877..f6b11ad 100755 --- a/zharko/site/system/models/account.php +++ b/zharko/site/system/models/account.php @@ -5,7 +5,20 @@ declare(strict_types=1); namespace zharko\site\models; // Files of the project -use zharko\site\models\core +use zharko\site\models\core; + +// Library for languages +use mirzaev\languages\language; + +// Baza database +use mirzaev\baza\database, + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; + +// Svoboda time +use svoboda\time\statement as svoboda; // Built-in libraries use Exception as exception, @@ -28,7 +41,7 @@ class account extends core * * @var string database Path to the database file */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'account.baza'; + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza'; /** * Database @@ -66,6 +79,52 @@ class account extends core ->connect($this->file); } + /** + * Write + * + * Create the account record in the database + * + * @return int|false The record identifier, if created + */ + public function write( + string $domain = '', + string $name = '', + string $mail = '', + string $password = '', + language $language = language::en, + &$errors = [] + ): int|false { + // Initializing the identifier + $identifier = $this->database->count() + 1; + + // Calculating the current timestamp + $timestamp = svoboda::timestamp(); + + // Initializing the record + $record = $this->database->record( + $identifier, + $domain, + $name, + $mail, + $password, + '', + '', + $language->value, + 1, + 1, + 0, + 0, + $timestamp, + $timestamp + ); + + // Creating the record in the database + $created = $this->database->write($record); + + // Exit (success) + return $created ? $identifier : false; + } + /** * Authorization * @@ -88,16 +147,16 @@ class account extends core // Found the account record if ( - $account->name_first !== $telegram->getFirstName() || - $account->name_second !== $telegram->getLastName() || - $account->domain !== $telegram->getUsername() + $account->name_first !== $telegram->getFirstName() || + $account->name_second !== $telegram->getLastName() || + $account->domain !== $telegram->getUsername() ) { // The telegram account was updated - + // Updating the account in the database $updated = $this->database->read( filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), - update: function (record &$record) use ($telegram){ + update: function (record &$record) use ($telegram) { // Writing new values into the record $record->name_first = $telegram->getFirstName(); $record->name_second = $telegram->getLastName(); @@ -151,4 +210,3 @@ class account extends core } } } - diff --git a/zharko/site/system/models/enumerations/language.php b/zharko/site/system/models/enumerations/language.php deleted file mode 100755 index 0e3f03c..0000000 --- a/zharko/site/system/models/enumerations/language.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @author zharko - */ -enum language -{ - case en; - case ru; - - /** - * Label - * - * Initialize label of the language - * - * @param language|null language Language into which to translate - * - * @return string Translated label of the language - */ - public function label(?language $language = language::en): string - { - // Exit (success) - return match ($this) { - language::en => match ($language) { - language::en => 'English', - language::ru => 'Английский' - }, - language::ru => match ($language) { - language::en => 'Russian', - language::ru => 'Русский' - } - }; - } - - /** - * Flag - * - * Initialize the flag emoji of the language - * - * @return string The flag emoji of the language - */ - public function flag(): string - { - // Exit (success) - return match ($this) { - language::en => '🇺🇸', - language::ru => '🇷🇺' - }; - } -} diff --git a/zharko/site/system/models/enumerations/session.php b/zharko/site/system/models/enumerations/session.php new file mode 100644 index 0000000..28070f8 --- /dev/null +++ b/zharko/site/system/models/enumerations/session.php @@ -0,0 +1,19 @@ + + */ +enum session +{ + case blake2b; + case blake2b_or_address; +} diff --git a/zharko/site/system/models/middlewares/account.php b/zharko/site/system/models/middlewares/account.php new file mode 100755 index 0000000..931e5a9 --- /dev/null +++ b/zharko/site/system/models/middlewares/account.php @@ -0,0 +1,43 @@ + + */ +class account extends middleware +{ + /** + * Authentication + * + * @return void + */ + public function authentication(callable $next, controller $controller): void + { + // Authorizing the account + $controller->account = account::authorization() ?? null; + + // Exit (success) + $next(); + } +} diff --git a/zharko/site/system/models/middlewares/session.php b/zharko/site/system/models/middlewares/session.php new file mode 100755 index 0000000..50bd523 --- /dev/null +++ b/zharko/site/system/models/middlewares/session.php @@ -0,0 +1,55 @@ + + */ +class session extends middleware +{ + /** + * Middleware + * + * @return void + */ + public function middleware(callable $next, controller $controller): void + { + // Initializing the session + $session = model::read(); + + if ($session instanceof session) { + // Found the session + + } + + // Exit (success) + $next(); + } +} diff --git a/zharko/site/system/models/session.php b/zharko/site/system/models/session.php new file mode 100755 index 0000000..8c13495 --- /dev/null +++ b/zharko/site/system/models/session.php @@ -0,0 +1,169 @@ + + */ +class session extends core +{ + /** + * File + * + * @var string database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'sessions.baza'; + + /** + * Database + * + * @var database $database The database + */ + public protected(set) database $database; + + /** + * Type + * + * @var varification Type of the session verification + */ + final public const verification VERIFICATION = verification::blake2b; + + /** + * Timer + * + * @var int The number of seconds after which the session is deactivated + */ + final public const int TIMER = 604800; + + /** + * Constructor + * + * @return void + */ + public function __construct() + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::utf8) + ->columns( + new column('identifier', type::integer_unsigned), + new column('expires', type::integer_unsigned), + new column('address', type::string, ['length' => 128]), + new column('x-forwarded-for', type::string, ['length' => 128]), + new column('referer', type::string, ['length' => 128]), + new column('useragent', type::string, ['length' => 256]), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->file); + } + + /** + * Write + * + * Create the session record in the database + * + * @return int|false The record identifier, if created + */ + public function write( + string $address = '', + string $x_forwarded_for = '', + string $referer = '', + string $useragent = '', + &$errors = [] + ): int|false { + // Initializing the identifier + $identifier = $this->database->count() + 1; + + // Calculating the current timestamp + $timestamp = svoboda::timestamp(); + + // Initializing the record + $record = $this->database->record( + $identifier, + $timestamp + static::TIMER, + $address, + $x_forwarded_for, + $referer, + $useragent, + $timestamp, + $timestamp + ); + + // Creating the record in the database + $created = $this->database->write($record); + + // Exit (success) + return $created ? $identifier : false; + } + + /** + * Read + * + * Read the session record from the database + * + * @return int|false The record identifier, if created + */ + public function read( + string $address = '', + string $x_forwarded_for = '', + string $referer = '', + string $useragent = '', + &$errors = [] + ): int|false { + // Initializing the identifier + $identifier = $this->database->count() + 1; + + // Calculating the current timestamp + $timestamp = svoboda::timestamp(); + + // Initializing the record + $record = $this->database->record( + $identifier, + $timestamp + static::TIMER, + $address, + $x_forwarded_for, + $referer, + $useragent, + $timestamp, + $timestamp + ); + + // Creating the record in the database + $created = $this->database->write($record); + + // Exit (success) + return $created ? $identifier : false; + } + +} diff --git a/zharko/site/system/public/index.php b/zharko/site/system/public/index.php index 9633c17..1e25fc1 100755 --- a/zharko/site/system/public/index.php +++ b/zharko/site/system/public/index.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace zharko\site; +// Files of the project +use zharko\site\models\middlewares\session; + // Framework for PHP use mirzaev\minimal\core, mirzaev\minimal\route, @@ -48,15 +51,12 @@ $core = new core(namespace: __NAMESPACE__); // Initializing routes $core->router ->write('/', new route('index', 'index'), 'GET') + ->write('/account/registration', new route('account', 'registration'), ['GET', 'PUT']) ; // Writing the global middleware -$core->router->middleware(new middleware(function(callable $next, controller $controller) { - // Authorizing the account - $controller->account = account::authorization() ?? null; - - $next(); -})); +$core->router->middleware(new session); +/* $core->router->middleware(new account); */ // Processing the request $core->start(); diff --git a/zharko/site/system/public/js/core.js b/zharko/site/system/public/js/core.js new file mode 100644 index 0000000..f150ef7 --- /dev/null +++ b/zharko/site/system/public/js/core.js @@ -0,0 +1,404 @@ +/** + * @name Core + * + * @description + * Core of the project + * + * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License + * @author Arsen Mirzaev Tatyano-Muradovich + */ +class core { + // Domain + static domain = window.location.hostname; + + // Language + static language = "en"; + + // Theme + static theme = window.getComputedStyle(document.getElementById('theme')); + + // Window + static window; + + // The "loading" element + static loading = document.getElementById("loading"); + + // The
element + static header = document.body.getElementsByTagName("header")[0]; + + // The