This commit is contained in:
2025-10-09 23:27:04 +07:00
parent 5a07ecccda
commit d454c29ee9
139 changed files with 181 additions and 9 deletions

View File

@@ -11,9 +11,9 @@
"license": "WTFPL",
"authors": [
{
"name": "zharko",
"email": "zharko@gmail.com",
"homepage": "https://zharko.page",
"name": "Arsen Mirzaev Tatyano-Muradovich",
"email": "arsen@mirzaev.sexy",
"homepage": "https://mirzaev.sexy",
"role": "Programmer"
}
],
@@ -23,7 +23,7 @@
},
"require": {
"php": "^8.4",
"mirzaev/minimal": "^3.6",
"mirzaev/minimal": "^3.7",
"mirzaev/baza": "^3.3",
"twig/twig": "^3.2",
"twig/extra-bundle": "^3.7",

View File

@@ -7,6 +7,7 @@ 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;
// Framework for PHP
@@ -20,6 +21,7 @@ use mirzaev\minimal\core as minimal,
*
* @package zharko\site\controllers
*
* @param account $account Account
* @param language $language Language
* @param response $response Response
* @param array $errors Registry of errors
@@ -32,6 +34,13 @@ use mirzaev\minimal\core as minimal,
*/
class core extends controller
{
/**
* Account
*
* @var account $account Account
*/
protected account $account;
/**
* Language
*

View File

@@ -42,7 +42,7 @@ final class index extends core
*/
public function index(): null
{
if (str_contains($this->request->headers['accept'], content::any->value)) {
if (str_contains($this->request->headers['accept'] ?? '', content::any->value)) {
// Request for any response
// Render page

View File

@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace zharko\site\models;
// Files of the project
use zharko\site\models\core
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime;
/**
* Account model
*
* @package zharko\site\models
*
* @method void __construct() Constructor
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
class account extends core
{
/**
* File
*
* @var string database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'account.baza';
/**
* Database
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* 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('domain', type::string, ['length' => 32]),
new column('name', type::string, ['length' => 128]),
new column('mail', type::string, ['length' => 128]),
new column('password', type::string, ['length' => 32]),
new column('session', type::string, ['length' => 256]),
new column('session_expired', type::string, ['length' => 32]),
new column('language', type::string, ['length' => 2]),
new column('authorized_system', type::char),
new column('authorized_settings', type::char),
new column('authorized_system_accounts', type::char),
new column('authorized_system_settings', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
}
/**
* Authorization
*
* Searches for the account record in the database
*
* @param telegram $telegram The telegram account
*
* @throws exception_runtime if update the account record in the database by the telegram account values
* @throws exception_runtime if failed to find the registered account
* @throws exception_runtime if failed to registrate the account
*
* @return record The account record from the database
*/
public function authorization(telegram $telegram): record
{
// Searching for the account in the database
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
if ($account instanceof record) {
// Found the account record
if (
$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){
// Writing new values into the record
$record->name_first = $telegram->getFirstName();
$record->name_second = $telegram->getLastName();
$record->domain = $telegram->getUsername();
$record->updated = svoboda::timestamp();
},
amount: 1
)[0] ?? null;
if ($updated instanceof record && $updated->values() !== $account->values()) {
// Updated the account in the database
// Exit (success)
return $updated;
} else {
// Not updated the account in the database
// Exit (fail)
throw new exception_runtime('Failed to update the account record in the database by the telegram account values');
}
}
// Exit (success)
return $account;
} else {
// Not found the account record
if ($this->registrate($telegram)) {
// Registered the account
// Searching for the registered account in the database
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
if ($account instanceof record) {
// Found the registered account
// Exit (success)
return $account;
} else {
// Not found the registered account
// Exit (fail)
throw new exception_runtime('Failed to find the registered account');
}
} else {
// Not registered the account
// Exit (fail)
throw new exception_runtime('Failed to registrate the account');
}
}
}
}

View File

@@ -20,7 +20,6 @@ use exception;
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
* @author zharko <mail@domain.zone>
*/
class core extends model
{

Some files were not shown because too many files have changed in this diff Show More