diff --git a/.gitignore b/.gitignore index 1dda020..0ad61ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -!.gitignore -composer.phar -vendor +!.gitignore +composer.phar +vendor diff --git a/LICENSE b/LICENSE index 7a3094a..e007a57 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,11 @@ -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -Version 2, December 2004 - -Copyright (C) 2004 Sam Hocevar - -Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. - -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. You just DO WHAT THE FUCK YOU WANT TO. +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md index 847127f..db592e3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# site-account - +# site-account + Site for intersite authentication \ No newline at end of file diff --git a/composer.json b/composer.json index d3920f4..cb5f10a 100644 --- a/composer.json +++ b/composer.json @@ -1,57 +1,57 @@ -{ - "name": "mirzaev/site-account", - "description": "API for intersite authentication", - "readme": "README.md", - "keywords": [ - "site", - "api", - "authentication", - "auth" - ], - "type": "site", - "homepage": "https://git.mirzaev.sexy/mirzaev/site-account", - "license": "WTFPL", - "authors": [ - { - "name": "Arsen Mirzaev Tatyano-Muradovich", - "email": "arsen@mirzaev.sexy", - "homepage": "https://mirzaev.sexy", - "role": "Programmer" - } - ], - "support": { - "email": "arsen@mirzaev.sexy", - "wiki": "https://git.mirzaev.sexy/mirzaev/site-account/wiki", - "issues": "https://git.mirzaev.sexy/mirzaev/site-account/issues" - }, - "funding": [ - { - "type": "funding", - "url": "https://fund.mirzaev.sexy" - } - ], - "require": { - "php": "~8.1", - "ext-sodium": "~8.1", - "mirzaev/minimal": "^2.0.x-dev", - "mirzaev/accounts": "~1.2.x-dev", - "mirzaev/arangodb": "^1.0.0", - "mirzaev/vk": "^5.0", - "triagens/arangodb": "~3.9.x-dev", - "twig/twig": "^3.4", - "guzzlehttp/guzzle": "^7.5" - }, - "require-dev": { - "phpunit/phpunit": "~9.5" - }, - "autoload": { - "psr-4": { - "mirzaev\\site\\account\\": "mirzaev/site/account/system" - } - }, - "autoload-dev": { - "psr-4": { - "mirzaev\\site\\account\\tests\\": "mirzaev/site/account/tests" - } - } -} +{ + "name": "mirzaev/site-account", + "description": "API for intersite authentication", + "readme": "README.md", + "keywords": [ + "site", + "api", + "authentication" + ], + "type": "site", + "homepage": "https://git.mirzaev.sexy/mirzaev/site-account", + "license": "WTFPL", + "authors": [ + { + "name": "Arsen Mirzaev Tatyano-Muradovich", + "email": "arsen@mirzaev.sexy", + "homepage": "https://mirzaev.sexy", + "role": "Programmer" + } + ], + "support": { + "email": "arsen@mirzaev.sexy", + "wiki": "https://git.mirzaev.sexy/mirzaev/site-account/wiki", + "issues": "https://git.mirzaev.sexy/mirzaev/site-account/issues" + }, + "funding": [ + { + "type": "funding", + "url": "https://fund.mirzaev.sexy" + } + ], + "require": { + "php": "~8.2", + "ext-sodium": "~8.2", + "mirzaev/minimal": "^2.0.x-dev", + "mirzaev/accounts": "~1.2.x-dev", + "mirzaev/arangodb": "^1.0.0", + "mirzaev/vk": "^5.0", + "triagens/arangodb": "~3.9.x-dev", + "twig/twig": "^3.4", + "guzzlehttp/guzzle": "^7.5", + "scripturadesign/markov": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "~9.5" + }, + "autoload": { + "psr-4": { + "mirzaev\\site\\account\\": "mirzaev/site/account/system" + } + }, + "autoload-dev": { + "psr-4": { + "mirzaev\\site\\account\\tests\\": "mirzaev/site/account/tests" + } + } +} diff --git a/composer.lock b/composer.lock index 1ceac43..b2c1f6f 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": "b562666ddbd12600f288a2949acc97d4", + "content-hash": "c0621deb07173185d918fd02e7551ca4", "packages": [ { "name": "guzzlehttp/guzzle", @@ -396,13 +396,13 @@ "source": { "type": "git", "url": "https://git.mirzaev.sexy/mirzaev/accounts", - "reference": "4d6df00dc9538c99d8eced6deebab55f1af2bf8a" + "reference": "aa93c4d26395025fa16bb65e8a40332ac352a742" }, "require": { - "ext-dom": "20031129", - "ext-libxml": "~8.1.1", - "guzzlehttp/guzzle": "^7.2", - "php": "~8.1" + "ext-dom": "*", + "ext-libxml": "*", + "guzzlehttp/guzzle": "^7.5", + "php": "~8.2" }, "require-dev": { "phpdocumentor/phpdocumentor": ">=2.9", @@ -442,7 +442,7 @@ "type": "funding" } ], - "time": "2022-11-05T23:48:10+00:00" + "time": "2023-02-17T08:36:36+00:00" }, { "name": "mirzaev/arangodb", @@ -932,17 +932,68 @@ "time": "2019-03-08T08:55:37+00:00" }, { - "name": "symfony/deprecation-contracts", - "version": "v3.1.1", + "name": "scripturadesign/markov", + "version": "v2.0.0", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" + "url": "https://github.com/scripturadesign/markov.git", + "reference": "ca6d51a5d8ce1e115708c2d38c49c397e515cae9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", + "url": "https://api.github.com/repos/scripturadesign/markov/zipball/ca6d51a5d8ce1e115708c2d38c49c397e515cae9", + "reference": "ca6d51a5d8ce1e115708c2d38c49c397e515cae9", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.4.0", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^4.15.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Scriptura\\Markov\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Martin Dilling-Hansen", + "email": "martindilling@gmail.com", + "homepage": "http://martindilling.com", + "role": "Developer" + } + ], + "description": "Markov Chain", + "homepage": "https://github.com/scripturadesign/markov", + "keywords": [ + "markov chain" + ], + "support": { + "issues": "https://github.com/scripturadesign/markov/issues", + "source": "https://github.com/scripturadesign/markov/tree/v2.0.0" + }, + "time": "2021-12-15T00:09:01+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "0121954c80fd17c18cf050fe73360e63bb43d4fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0121954c80fd17c18cf050fe73360e63bb43d4fb", + "reference": "0121954c80fd17c18cf050fe73360e63bb43d4fb", "shasum": "" }, "require": { @@ -951,7 +1002,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.1-dev" + "dev-main": "3.3-dev" }, "thanks": { "name": "symfony/contracts", @@ -980,7 +1031,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" }, "funding": [ { @@ -996,7 +1047,7 @@ "type": "tidelift" } ], - "time": "2022-02-25T11:15:52+00:00" + "time": "2023-02-02T07:48:03+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1226,16 +1277,16 @@ }, { "name": "twig/twig", - "version": "v3.4.3", + "version": "v3.5.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58" + "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58", - "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/a6e0510cc793912b451fd40ab983a1d28f611c15", + "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15", "shasum": "" }, "require": { @@ -1250,7 +1301,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "3.5-dev" } }, "autoload": { @@ -1286,7 +1337,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.4.3" + "source": "https://github.com/twigphp/Twig/tree/v3.5.1" }, "funding": [ { @@ -1298,36 +1349,36 @@ "type": "tidelift" } ], - "time": "2022-09-28T08:42:51+00:00" + "time": "2023-02-08T07:49:20+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -1354,7 +1405,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -1370,7 +1421,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "myclabs/deep-copy", @@ -1433,16 +1484,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.2", + "version": "v4.15.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc" + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc", - "reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039", + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039", "shasum": "" }, "require": { @@ -1483,9 +1534,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3" }, - "time": "2022-11-12T15:38:23+00:00" + "time": "2023-01-16T22:05:37+00:00" }, { "name": "phar-io/manifest", @@ -1600,23 +1651,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.19", + "version": "9.2.25", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559" + "reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c77b56b63e3d2031bd8997fcec43c1925ae46559", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e2b40518197a8c0d4b08bc34dfff1c99c508954", + "reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.14", + "nikic/php-parser": "^4.15", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -1665,7 +1716,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.19" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.25" }, "funding": [ { @@ -1673,7 +1724,7 @@ "type": "github" } ], - "time": "2022-11-18T07:47:47+00:00" + "time": "2023-02-25T05:32:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1918,20 +1969,20 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.26", + "version": "9.6.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2" + "reference": "9125ee085b6d95e78277dc07aa1f46f9e0607b8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/851867efcbb6a1b992ec515c71cdcf20d895e9d2", - "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9125ee085b6d95e78277dc07aa1f46f9e0607b8d", + "reference": "9125ee085b6d95e78277dc07aa1f46f9e0607b8d", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1", + "doctrine/instantiator": "^1.3.1 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", @@ -1969,7 +2020,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.5-dev" + "dev-master": "9.6-dev" } }, "autoload": { @@ -2000,7 +2051,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.26" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.4" }, "funding": [ { @@ -2016,7 +2067,7 @@ "type": "tidelift" } ], - "time": "2022-10-28T06:00:21+00:00" + "time": "2023-02-27T13:06:37+00:00" }, { "name": "sebastian/cli-parser", @@ -2384,16 +2435,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { @@ -2435,7 +2486,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -2443,7 +2494,7 @@ "type": "github" } ], - "time": "2022-04-03T09:37:03+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", @@ -2757,16 +2808,16 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { @@ -2805,10 +2856,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -2816,7 +2867,7 @@ "type": "github" } ], - "time": "2020-10-26T13:17:30+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", @@ -2875,16 +2926,16 @@ }, { "name": "sebastian/type", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { @@ -2919,7 +2970,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -2927,7 +2978,7 @@ "type": "github" } ], - "time": "2022-09-12T14:47:03+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", @@ -3043,8 +3094,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.1", - "ext-sodium": "~8.1" + "php": "~8.2", + "ext-sodium": "~8.2" }, "platform-dev": [], "plugin-api-version": "2.3.0" diff --git "a/mirzaev/site/account/system/\\" "b/mirzaev/site/account/system/\\" new file mode 100644 index 0000000..369117c --- /dev/null +++ "b/mirzaev/site/account/system/\\" @@ -0,0 +1,74 @@ + + */ +final class api extends core +{ + /** + * Проверить существование + * + * @param array $parameters Параметры запроса + * + * @return string JSON с параметром exist + */ + public function invite_verify(array $parameters = []): string + { + // Инициализация буфера ответа + $return = ['errors' => &$this->errors]; + + // Запрос проверки на существование приглашения + $invite = invite::read($parameters['key'], $this->errors['account']); + + $return['exist'] = isset($invite); + + if ($parameters['from'] == 1) $return['from'] = ['login' => 'mirzaev'] ?? $invite->from(); + + // Запись заголовка ответа + header('Content-Type: application/json'); + + return json_encode($return); + } + + /** + * Сгенерировать классический пароль + * + * @param array $parameters Параметры запроса + * + * @return string JSON с параметром password + */ + public function password_classic(array $parameters = []): string + { + // Запись заголовка ответа + header('Content-Type: application/json'); + + return json_encode(['password' => password::classic((int) $parameters['length'], $this->errors), 'errors' => $this->errors]); + } + + /** + * Сгенерировать мнемонический пароль + * + * @param array $parameters Параметры запроса + * + * @return string JSON с параметром password + */ + public function password_mnemonic(array $parameters = []): string + { + // Запись заголовка ответа + header('Content-Type: application/json'); + + return json_encode(['password' => password::mnemonic((int) $parameters['length'], $this->errors), 'errors' => $this->errors]); + } +} diff --git a/mirzaev/site/account/system/controllers/account.php b/mirzaev/site/account/system/controllers/account.php new file mode 100644 index 0000000..e9385bb --- /dev/null +++ b/mirzaev/site/account/system/controllers/account.php @@ -0,0 +1,149 @@ + + */ +final class account extends core +{ + /** + * Страница профиля + * + * @param array $parameters Параметры запроса + */ + public function index(array $parameters = []): ?string + { + return null; + } + + /** + * Инициализация + * + * @param array $parameters Параметры запроса + */ + public function initialization(array $parameters = []): ?string + { + if ($this->variables['account'] instanceof _document) { + // Найден аккаунт + + if ($this->variables['vk'] instanceof _document) { + // Найден аккаунт ВКонтакте + + // Инициализация данных аккаунта ВКонтакте + vk::parse($this->variables['vk'], $this->variables['errors']['vk']); + } + + // Запись кода ответа + http_response_code(200); + + return null; + } else { + // Не найден аккаунт + + // Запись кода ответа + http_response_code(401); + + // Запись заголовка ответа с ключом аккаунта + header('session: ' . $this->variables['session']->hash); + + return null; + } + + // Запись кода ответа + http_response_code(500); + + return null; + } + + /** + * Связь аккаунта с аккаунтом ВКонтакте + * + * @param array $parameters Параметры запроса + */ + public function connect(array $parameters = []): ?string + { + if ($this->variables['session']->hash === $parameters['state']) { + // Совпадает хеш сессии с полученным хешем из ответа ВКонтакте + + if (!empty($response = vk::key($parameters['code'], $this->variables['errors']['vk']))) { + // Получены данные аккаунта ВКонтакте + + if (($this->variables['vk'] = vk::initialization($response, $this->variables['errors']['vk'])) instanceof _document) { + // Инициализирован аккаунт ВКонтакте + + if (($this->variables['account'] = vk::account($this->variables['vk'])) instanceof _document) { + // Найден аккаунт (существующий) + + if (session::connect($this->variables['session'], $this->variables['account'], $this->variables['errors']['session'])) { + // Связана сессия с аккаунтом + } + } else if (($this->variables['account'] = model::create($this->variables['errors']['account'])) instanceof _document) { + // Найден аккаунт (создан новый) + + if (session::connect($this->variables['session'], $this->variables['account'], $this->variables['errors']['session'])) { + // Связана сессия с аккаунтом + + if (account::connect($this->variables['account'], $this->variables['vk'], $this->variables['errors']['account'])) { + // Связан аккаунт с аккаунтом ВКонтакте + } + } + } + + // Инициализация робота для аккаунта ВКонтакте + $this->vk = api::init()->user(key: $this->variables['vk']->access['key']); + + if ($this->variables['vk'] instanceof _document) { + // Инициализирован робот для аккаунта ВКонтакте + + // Инициализация данных аккаунта ВКонтакте + $data = vk::parse($this->vk, $this->variables['errors']['vk']); + var_dump($data); + die; + + if ($data instanceof stdClass) { + // Получены данные ВКонтакте + + // Запись в базу данных + vk::update($this->variables['vk'], $data, $this->variables['errors']['vk']); + } + } + } + } + } + + // Генерация представления + return $this->view->render(DIRECTORY_SEPARATOR . 'account' . DIRECTORY_SEPARATOR . 'vk.html', $this->variables); + } + + /** + * Генерация панели аккаунта + * + * @param array $parameters Параметры запроса + */ + public function panel(array $parameters = []): ?string + { + // Генерация представления + return $this->view->render(DIRECTORY_SEPARATOR . 'account' . DIRECTORY_SEPARATOR . 'panel.html', $this->variables); + } +} diff --git a/mirzaev/site/account/system/controllers/account_controller.php b/mirzaev/site/account/system/controllers/account_controller.php deleted file mode 100644 index bdf93f3..0000000 --- a/mirzaev/site/account/system/controllers/account_controller.php +++ /dev/null @@ -1,146 +0,0 @@ - - */ -final class account_controller extends core -{ - /** - * Страница профиля - * - * @param array $parameters Параметры запроса - */ - public function index(array $parameters = []): ?string - { - return null; - } - - /** - * Инициализация - * - * @param array $parameters Параметры запроса - */ - public function initialization(array $parameters = []): ?string - { - if ($this->variables['account'] instanceof _document) { - // Найден аккаунт - - if ($this->variables['vk'] instanceof _document) { - // Найден аккаунт ВКонтакте - - // Инициализация данных аккаунта ВКонтакте - vk::parse($this->variables['vk'], $this->variables['errors']['vk']); - } - - // Запись кода ответа - http_response_code(200); - - return null; - } else { - // Не найден аккаунт - - // Запись кода ответа - http_response_code(401); - - // Запись заголовка ответа с ключом аккаунта - header('session: ' . $this->variables['session']->hash); - - return null; - } - - // Запись кода ответа - http_response_code(500); - - return null; - } - - /** - * Связь аккаунта с аккаунтом ВКонтакте - * - * @param array $parameters Параметры запроса - */ - public function connect(array $parameters = []): ?string - { - if ($this->variables['session']->hash === $parameters['state']) { - // Совпадает хеш сессии с полученным хешем из ответа ВКонтакте - - if (!empty($response = vk::key($parameters['code'], $this->variables['errors']['vk']))) { - // Получены данные аккаунта ВКонтакте - - if (($this->variables['vk'] = vk::initialization($response, $this->variables['errors']['vk'])) instanceof _document) { - // Инициализирован аккаунт ВКонтакте - - if (($this->variables['account'] = vk::account($this->variables['vk'])) instanceof _document) { - // Найден аккаунт (существующий) - - if (session::connect($this->variables['session'], $this->variables['account'], $this->variables['errors']['session'])) { - // Связана сессия с аккаунтом - } - } else if (($this->variables['account'] = account::create($this->variables['errors']['account'])) instanceof _document) { - // Найден аккаунт (создан новый) - - if (session::connect($this->variables['session'], $this->variables['account'], $this->variables['errors']['session'])) { - // Связана сессия с аккаунтом - - if (account::connect($this->variables['account'], $this->variables['vk'], $this->variables['errors']['account'])) { - // Связан аккаунт с аккаунтом ВКонтакте - } - } - } - - // Инициализация робота для аккаунта ВКонтакте - $this->vk = api::init()->user(key: $this->variables['vk']->access['key']); - - if ($this->variables['vk'] instanceof _document) { - // Инициализирован робот для аккаунта ВКонтакте - - // Инициализация данных аккаунта ВКонтакте - $data = vk::parse($this->vk, $this->variables['errors']['vk']); - var_dump($data); die; - - if ($data instanceof stdClass) { - // Получены данные ВКонтакте - - // Запись в базу данных - vk::update($this->variables['vk'], $data, $this->variables['errors']['vk']); - } - } - } - } - } - - // Генерация представления - return $this->view->render(DIRECTORY_SEPARATOR . 'account' . DIRECTORY_SEPARATOR . 'vk.html', $this->variables); - } - - /** - * Генерация панели аккаунта - * - * @param array $parameters Параметры запроса - */ - public function panel(array $parameters = []): ?string - { - // Генерация представления - return $this->view->render(DIRECTORY_SEPARATOR . 'account' . DIRECTORY_SEPARATOR . 'panel.html', $this->variables); - } -} diff --git a/mirzaev/site/account/system/controllers/api.php b/mirzaev/site/account/system/controllers/api.php new file mode 100644 index 0000000..0760a33 --- /dev/null +++ b/mirzaev/site/account/system/controllers/api.php @@ -0,0 +1,73 @@ + + */ +final class api extends core +{ + use errors; + + /** + * Сгенерировать пароль + * + * @param array $parameters Параметры запроса + * + * @return string JSON-документ с запрашиваемыми параметрами + */ + public function password(array $parameters = []): string + { + // Инициализация буфера ответа + $buffer = []; + + // Инициализация реестра возвращаемых параметров + $return = explode(',', $parameters['return'], 50); + + // Инициализация значений по умолчению + $parameters['length'] ??= 6; + $parameters['type'] ??= 'classic'; + + try { + // Проверка параметров на соответствие требованиям + if (($parameters['length'] = (int) $parameters['length']) === 0) throw new exception('Минимальная длина генерируемого пароля: 1 символ'); + if ($parameters['type'] !== 'classic' && $parameters['type'] !== 'mnemonic') throw new exception('Допустимые типы пароля: "mnemonic", "classic"'); + + // Генерация ответа по запрашиваемым параметрам + foreach ($return as $parameter) match ($parameter) { + 'password' => $buffer['password'] = password::{$parameters['type'] ?? 'classic'}($parameters['length'], $this->errors), + 'errors' => null, + default => throw new exception("Параметр не найден: $parameter") + }; + } catch (exception $e) { + // Запись в журнал ошибок + $this->errors[] = [ + 'text' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'stack' => $e->getTrace() + ]; + } + + // Запись реестра ошибок в буфер ответа + if (in_array('errors', $return, true)) $buffer['errors'] = self::parse_only_text($this->errors); + + // Запись заголовка ответа + header('Content-Type: application/json'); + + return json_encode($buffer); + } +} diff --git a/mirzaev/site/account/system/controllers/core.php b/mirzaev/site/account/system/controllers/core.php index 09c9a22..da52236 100644 --- a/mirzaev/site/account/system/controllers/core.php +++ b/mirzaev/site/account/system/controllers/core.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace mirzaev\site\account\controllers; // Файлы проекта -use mirzaev\site\account\views\manager; +use mirzaev\site\account\views\templater; use mirzaev\site\account\models\core as models; -use mirzaev\site\account\models\account_model as account; -use mirzaev\site\account\models\session_model as session; +use mirzaev\site\account\models\account; +use mirzaev\site\account\models\session; // Библиотека для ArangoDB use ArangoDBClient\Document as _document; @@ -28,73 +28,76 @@ use mirzaev\vk\robots\user as robot; */ class core extends controller { - /** - * Переменные окружения - */ - protected robot $vk; + /** + * Переменные окружения + */ + protected robot $vk; - /** - * Переменные окружения - */ - protected array $variables = []; + /** + * Инстанция сессии + */ + public session $session; - /** - * Конструктор - * - * @return void - */ - public function __construct() - { - parent::__construct(); + /** + * Инстанция аккаунта + */ + public ?account $account; - // Инициализация ядра моделей (соединение с базой данных...) - new models(); + /** + * Постфикс + */ + public string $postfix = ''; - // Инициализация журнала ошибок - $this->variables['errors'] = [ - 'session' => [], - 'account' => [], - 'vk' => [] - ]; + /** + * Реестр ошибок + */ + public array $errors = [ + 'session' => [], + 'account' => [] + ]; - // Инициализация даты до которой будет активна сессия - $expires = time() + 604800; + /** + * Конструктор + * + * @return void + */ + public function __construct() + { + parent::__construct(); - // Инициализация сессии (без журналирования) - $this->variables['session'] = session::initialization($_COOKIE["session"] ?? null, $expires) ?? header('Location: https://mirzaev.sexy/error?code=500&text=Не+удалось+инициализировать+сессию'); + // Инициализация ядра моделей (соединение с базой данных...) + new models(); - if ($_COOKIE["session"] ?? null !== $this->variables['session']->hash) { - // Изменился хеш сессии (подразумевается, что сессия устарела) + // Инициализация шаблонизатора представлений + $this->view = new templater; - // Запись хеша новой сессии - setcookie('session', $this->variables['session']->hash, [ - 'expires' => $expires, - 'domain' => 'mirzaev.sexy', - 'path' => '/', - 'secure' => true, - 'httponly' => true, - 'samesite' => 'strict' - ]); - } + // Инициализация даты до которой будет активна сессия + $expires = time() + 604800; - // Инициализация аккаунта (без журналирования) - $this->variables['account'] = session::account($this->variables['session']); + // Инициализация сессии (без журналирования) + $this->session = new session($_COOKIE["session"] ?? null, $expires) ?? + header('Location: https://mirzaev.sexy/error?code=500&text=Не+удалось+инициализировать+сессию'); - if ($this->variables['account'] instanceof _document) { - // Инициализирован аккаунт + if ($_COOKIE["session"] ?? null !== $this->session->hash) { + // Изменился хеш сессии (подразумевается, что сессия устарела) - // Инициализация аккаунта ВКонтакте (без журналирования) - $this->variables['vk'] = account::vk($this->variables['account']); - - if ($this->variables['vk'] instanceof _document) { - // Инициализирован аккаунт ВКонтакте - - // Инициализация робота для аккаунта ВКонтакте - $this->vk = vk::init()->user(key: $this->variables['vk']->access['key']); - } else unset($this->variables['account'], $this->variables['vk']); - } - - // Инициализация препроцессора представления - $this->view = new manager; + // Запись хеша новой сессии + setcookie('session', $this->session->hash, [ + 'expires' => $expires, + 'domain' => 'mirzaev.sexy', + 'path' => '/', + 'secure' => true, + 'httponly' => true, + 'samesite' => 'strict' + ]); } + + // Инициализация аккаунта (без журналирования) + $this->account = $this->session->account(); + + if ($this->account instanceof _document) { + // Инициализирован аккаунт + + } + } } diff --git a/mirzaev/site/account/system/controllers/error_controller.php b/mirzaev/site/account/system/controllers/error.php similarity index 82% rename from mirzaev/site/account/system/controllers/error_controller.php rename to mirzaev/site/account/system/controllers/error.php index d30b8fd..53e8503 100644 --- a/mirzaev/site/account/system/controllers/error_controller.php +++ b/mirzaev/site/account/system/controllers/error.php @@ -1,44 +1,44 @@ - - */ -final class error_controller extends core -{ - /** - * Страница с ошибкой - * - * @param array $parameters - */ - public function index(array $parameters = []): ?string - { - // Запись текста ошибки в переменную окружения - $this->variables['text'] = $parameters['text'] ?? null; - - if (isset($parameters['code'])) { - // Получен код ошибки - - // Запись кода ошибки в переменную окружения - $this->variables['code'] = $parameters['code']; - - // Запись кода ответа - http_response_code($parameters['code']); - - // Генерация представления - return $this->view->render(DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR . 'index.html', $this->variables); - } - - // Генерация представления - return $this->view->render(DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR . ($parameters['code'] ?? 'index') . '.html', $this->variables); - } -} + + */ +final class error extends core +{ + /** + * Страница с ошибкой + * + * @param array $parameters + */ + public function index(array $parameters = []): ?string + { + // Запись текста ошибки в переменную окружения + $this->view->text = $parameters['text'] ?? null; + + if (isset($parameters['code'])) { + // Получен код ошибки + + // Запись кода ошибки в переменную окружения + $this->view->code = $parameters['code']; + + // Запись кода ответа + http_response_code($parameters['code']); + + // Генерация представления + return $this->view->render(DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR . 'index.html'); + } + + // Генерация представления + return $this->view->render(DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR . ($parameters['code'] ?? 'index') . '.html'); + } +} diff --git a/mirzaev/site/account/system/controllers/graph_controller.php b/mirzaev/site/account/system/controllers/graph.php similarity index 95% rename from mirzaev/site/account/system/controllers/graph_controller.php rename to mirzaev/site/account/system/controllers/graph.php index 8ccff1f..16a7307 100644 --- a/mirzaev/site/account/system/controllers/graph_controller.php +++ b/mirzaev/site/account/system/controllers/graph.php @@ -1,59 +1,59 @@ - - */ -final class graph_controller extends core -{ - /** - * Страница с графиком - * - * Можно использовать совместно с элементом