kernel update

This commit is contained in:
Kavalar 2024-12-16 14:26:13 +03:00
parent 589cf81e49
commit f5ad07c04a
77 changed files with 2067 additions and 251 deletions

View File

@ -1,13 +1,23 @@
APP_NAME="It Guild Micro Framework"
DB_HOST=localhost DB_HOST=localhost
DB_USER=root DB_USER={db_user}
DB_DRIVER=mysql DB_DRIVER=mysql
DB_PASSWORD=123edsaqw DB_PASSWORD={db_password}
DB_NAME=mfw DB_NAME={db_name}
DB_CHARSET=utf8 DB_CHARSET=utf8mb4
DB_COLLATION=utf8_unicode_ci DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX='' DB_PREFIX=''
VIEWS_PATH=/views VIEWS_PATH=/views
VIEWS_CACHE_PATH=/views_cache VIEWS_CACHE_PATH=/views_cache
MAIL_SMTP_HOST=smtp.mail.ru
MAIL_SMTP_PORT=587
MAIL_SMTP_USERNAME=username@mail.ru
MAIL_SMTP_PASSWORD=somepassword
MODULE_SHOP_URL='http://igfs.loc'
MODULE_SHOP_TOKEN='your token'
SECRET_KEY='' SECRET_KEY=''

View File

@ -1,7 +1,8 @@
<?php <?php
$secure_config = [ $secure_config = [
'token_type' => 'JWT', // random_bytes, md5, crypt, hash, JWT 'web_auth_type' => 'email_code', // login_password, email_code
'token_type' => 'crypt', // random_bytes, md5, crypt, hash, JWT
'token_expired_time' => "+30 days", // +1 day 'token_expired_time' => "+30 days", // +1 day
]; ];

View File

@ -18,7 +18,8 @@
"josantonius/session": "^2.0", "josantonius/session": "^2.0",
"firebase/php-jwt": "^6.10", "firebase/php-jwt": "^6.10",
"k-adam/env-editor": "^2.0", "k-adam/env-editor": "^2.0",
"guzzlehttp/guzzle": "^7.9" "guzzlehttp/guzzle": "^7.9",
"phpmailer/phpmailer": "^6.9"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

255
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9b8653e1a4f451d6e125cb1732ffdeef", "content-hash": "18fbb67ed0b66029e924b0a6d32f646f",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -275,16 +275,16 @@
}, },
{ {
"name": "firebase/php-jwt", "name": "firebase/php-jwt",
"version": "v6.10.1", "version": "v6.10.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/firebase/php-jwt.git", "url": "https://github.com/firebase/php-jwt.git",
"reference": "500501c2ce893c824c801da135d02661199f60c5" "reference": "30c19ed0f3264cb660ea496895cfb6ef7ee3653b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/500501c2ce893c824c801da135d02661199f60c5", "url": "https://api.github.com/repos/firebase/php-jwt/zipball/30c19ed0f3264cb660ea496895cfb6ef7ee3653b",
"reference": "500501c2ce893c824c801da135d02661199f60c5", "reference": "30c19ed0f3264cb660ea496895cfb6ef7ee3653b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -332,9 +332,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/firebase/php-jwt/issues", "issues": "https://github.com/firebase/php-jwt/issues",
"source": "https://github.com/firebase/php-jwt/tree/v6.10.1" "source": "https://github.com/firebase/php-jwt/tree/v6.10.2"
}, },
"time": "2024-05-18T18:05:11+00:00" "time": "2024-11-24T11:22:49+00:00"
}, },
{ {
"name": "graham-campbell/result-type", "name": "graham-campbell/result-type",
@ -725,16 +725,16 @@
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "a01a9d0799700bf34ab3797988fdd5f420d42bfe" "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/a01a9d0799700bf34ab3797988fdd5f420d42bfe", "url": "https://api.github.com/repos/illuminate/collections/zipball/fd2103ddc121449a7926fc34a9d220e5b88183c1",
"reference": "a01a9d0799700bf34ab3797988fdd5f420d42bfe", "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -776,20 +776,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-15T15:43:48+00:00" "time": "2024-11-27T14:51:56+00:00"
}, },
{ {
"name": "illuminate/conditionable", "name": "illuminate/conditionable",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/conditionable.git", "url": "https://github.com/illuminate/conditionable.git",
"reference": "362dd761b9920367bca1427a902158225e9e3a23" "reference": "911df1bda950a3b799cf80671764e34eede131c6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/conditionable/zipball/362dd761b9920367bca1427a902158225e9e3a23", "url": "https://api.github.com/repos/illuminate/conditionable/zipball/911df1bda950a3b799cf80671764e34eede131c6",
"reference": "362dd761b9920367bca1427a902158225e9e3a23", "reference": "911df1bda950a3b799cf80671764e34eede131c6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -822,20 +822,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-06-28T20:10:30+00:00" "time": "2024-11-21T16:28:56+00:00"
}, },
{ {
"name": "illuminate/container", "name": "illuminate/container",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/container.git", "url": "https://github.com/illuminate/container.git",
"reference": "6e31eb49e9c9e68356a55cd8f18fb8830b8158cd" "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/container/zipball/6e31eb49e9c9e68356a55cd8f18fb8830b8158cd", "url": "https://api.github.com/repos/illuminate/container/zipball/b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
"reference": "6e31eb49e9c9e68356a55cd8f18fb8830b8158cd", "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -873,20 +873,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-14T15:31:35+00:00" "time": "2024-11-21T20:07:31+00:00"
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
"reference": "44c15aec6ea0d997e0885aa5b04876fe8a141433" "reference": "184317f701ba20ca265e36808ed54b75b115972d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/44c15aec6ea0d997e0885aa5b04876fe8a141433", "url": "https://api.github.com/repos/illuminate/contracts/zipball/184317f701ba20ca265e36808ed54b75b115972d",
"reference": "44c15aec6ea0d997e0885aa5b04876fe8a141433", "reference": "184317f701ba20ca265e36808ed54b75b115972d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -921,7 +921,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-15T15:40:33+00:00" "time": "2024-11-25T15:33:38+00:00"
}, },
{ {
"name": "illuminate/database", "name": "illuminate/database",
@ -1060,7 +1060,7 @@
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
@ -1106,16 +1106,16 @@
}, },
{ {
"name": "illuminate/support", "name": "illuminate/support",
"version": "v11.32.0", "version": "v11.34.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/support.git", "url": "https://github.com/illuminate/support.git",
"reference": "213bc04ed2a75dac441e602df4568154c36a3670" "reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/213bc04ed2a75dac441e602df4568154c36a3670", "url": "https://api.github.com/repos/illuminate/support/zipball/2b718a86571baed50fdc5d5748a846c2e58e07eb",
"reference": "213bc04ed2a75dac441e602df4568154c36a3670", "reference": "2b718a86571baed50fdc5d5748a846c2e58e07eb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1127,9 +1127,9 @@
"illuminate/conditionable": "^11.0", "illuminate/conditionable": "^11.0",
"illuminate/contracts": "^11.0", "illuminate/contracts": "^11.0",
"illuminate/macroable": "^11.0", "illuminate/macroable": "^11.0",
"nesbot/carbon": "^2.72.2|^3.0", "nesbot/carbon": "^2.72.2|^3.4",
"php": "^8.2", "php": "^8.2",
"voku/portable-ascii": "^2.0" "voku/portable-ascii": "^2.0.2"
}, },
"conflict": { "conflict": {
"tightenco/collect": "<5.5.33" "tightenco/collect": "<5.5.33"
@ -1145,7 +1145,7 @@
"symfony/process": "Required to use the composer class (^7.0).", "symfony/process": "Required to use the composer class (^7.0).",
"symfony/uid": "Required to use Str::ulid() (^7.0).", "symfony/uid": "Required to use Str::ulid() (^7.0).",
"symfony/var-dumper": "Required to use the dd function (^7.0).", "symfony/var-dumper": "Required to use the dd function (^7.0).",
"vlucas/phpdotenv": "Required to use the Env class and env helper (^5.4.1)." "vlucas/phpdotenv": "Required to use the Env class and env helper (^5.6.1)."
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@ -1178,7 +1178,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-11-14T16:30:16+00:00" "time": "2024-11-27T14:58:17+00:00"
}, },
{ {
"name": "itguild/eloquent-table", "name": "itguild/eloquent-table",
@ -1217,11 +1217,11 @@
}, },
{ {
"name": "itguild/forms", "name": "itguild/forms",
"version": "0.1.4", "version": "0.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.itguild.info/ItGuild/forms_bundle.git", "url": "https://git.itguild.info/ItGuild/forms_bundle.git",
"reference": "ddb17cc47360910b3875b88e10e14f91fcd875be" "reference": "45e57367d3f9571fde2b82fa2fd8126469ba6db6"
}, },
"require": { "require": {
"itguild/php-cg-select-v2": "^0.1.0", "itguild/php-cg-select-v2": "^0.1.0",
@ -1245,7 +1245,7 @@
"email": "apuc06@mail.ru" "email": "apuc06@mail.ru"
} }
], ],
"time": "2024-09-10T08:41:16+00:00" "time": "2024-11-28T10:18:58+00:00"
}, },
{ {
"name": "itguild/php-cg-select-v2", "name": "itguild/php-cg-select-v2",
@ -1276,11 +1276,11 @@
}, },
{ {
"name": "itguild/tables", "name": "itguild/tables",
"version": "1.0.8", "version": "1.0.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.itguild.info/ItGuild/tables", "url": "https://git.itguild.info/ItGuild/tables",
"reference": "5f46431d4562d2b4d8bff43b446fef82ecf73b83" "reference": "5effacf12fd68d31181304562deb7331cf42c1db"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -1298,7 +1298,7 @@
"email": "apuc06@mail.ru" "email": "apuc06@mail.ru"
} }
], ],
"time": "2024-10-11T13:31:11+00:00" "time": "2024-11-28T08:57:17+00:00"
}, },
{ {
"name": "josantonius/session", "name": "josantonius/session",
@ -1607,6 +1607,87 @@
], ],
"time": "2024-11-07T17:46:48+00:00" "time": "2024-11-07T17:46:48+00:00"
}, },
{
"name": "phpmailer/phpmailer",
"version": "v6.9.3",
"source": {
"type": "git",
"url": "https://github.com/PHPMailer/PHPMailer.git",
"reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/2f5c94fe7493efc213f643c23b1b1c249d40f47e",
"reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-filter": "*",
"ext-hash": "*",
"php": ">=5.5.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"doctrine/annotations": "^1.2.6 || ^1.13.3",
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpcompatibility/php-compatibility": "^9.3.5",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.7.2",
"yoast/phpunit-polyfills": "^1.0.4"
},
"suggest": {
"decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication",
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
"ext-openssl": "Needed for secure SMTP sending and DKIM signing",
"greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
"psr/log": "For optional PSR-3 debug logging",
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPMailer\\PHPMailer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-only"
],
"authors": [
{
"name": "Marcus Bointon",
"email": "phpmailer@synchromedia.co.uk"
},
{
"name": "Jim Jagielski",
"email": "jimjag@gmail.com"
},
{
"name": "Andy Prevost",
"email": "codeworxtech@users.sourceforge.net"
},
{
"name": "Brent R. Matzelle"
}
],
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"support": {
"issues": "https://github.com/PHPMailer/PHPMailer/issues",
"source": "https://github.com/PHPMailer/PHPMailer/tree/v6.9.3"
},
"funding": [
{
"url": "https://github.com/Synchro",
"type": "github"
}
],
"time": "2024-11-24T18:04:13+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.9.3", "version": "1.9.3",
@ -2139,16 +2220,16 @@
}, },
{ {
"name": "symfony/clock", "name": "symfony/clock",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/clock.git", "url": "https://github.com/symfony/clock.git",
"reference": "97bebc53548684c17ed696bc8af016880f0f098d" "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/clock/zipball/97bebc53548684c17ed696bc8af016880f0f098d", "url": "https://api.github.com/repos/symfony/clock/zipball/b81435fbd6648ea425d1ee96a2d8e68f4ceacd24",
"reference": "97bebc53548684c17ed696bc8af016880f0f098d", "reference": "b81435fbd6648ea425d1ee96a2d8e68f4ceacd24",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2193,7 +2274,7 @@
"time" "time"
], ],
"support": { "support": {
"source": "https://github.com/symfony/clock/tree/v7.1.6" "source": "https://github.com/symfony/clock/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2209,20 +2290,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-25T14:20:29+00:00" "time": "2024-09-25T14:21:43+00:00"
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v3.5.0", "version": "v3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2260,7 +2341,7 @@
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
}, },
"funding": [ "funding": [
{ {
@ -2276,20 +2357,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-04-18T09:32:20+00:00" "time": "2024-09-25T14:20:29+00:00"
}, },
{ {
"name": "symfony/finder", "name": "symfony/finder",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/finder.git", "url": "https://github.com/symfony/finder.git",
"reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8" "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/2cb89664897be33f78c65d3d2845954c8d7a43b8", "url": "https://api.github.com/repos/symfony/finder/zipball/6de263e5868b9a137602dd1e33e4d48bfae99c49",
"reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8", "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2324,7 +2405,7 @@
"description": "Finds files and directories via an intuitive fluent interface", "description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/finder/tree/v7.1.6" "source": "https://github.com/symfony/finder/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2340,7 +2421,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-10-01T08:31:23+00:00" "time": "2024-10-23T06:56:12+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@ -2735,20 +2816,21 @@
}, },
{ {
"name": "symfony/translation", "name": "symfony/translation",
"version": "v7.1.6", "version": "v7.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation.git", "url": "https://github.com/symfony/translation.git",
"reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f" "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/b9f72ab14efdb6b772f85041fa12f820dee8d55f", "url": "https://api.github.com/repos/symfony/translation/zipball/dc89e16b44048ceecc879054e5b7f38326ab6cc5",
"reference": "b9f72ab14efdb6b772f85041fa12f820dee8d55f", "reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.2", "php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/translation-contracts": "^2.5|^3.0" "symfony/translation-contracts": "^2.5|^3.0"
}, },
@ -2809,7 +2891,7 @@
"description": "Provides tools to internationalize your application", "description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/translation/tree/v7.1.6" "source": "https://github.com/symfony/translation/tree/v7.2.0"
}, },
"funding": [ "funding": [
{ {
@ -2825,20 +2907,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-28T12:35:13+00:00" "time": "2024-11-12T20:47:56+00:00"
}, },
{ {
"name": "symfony/translation-contracts", "name": "symfony/translation-contracts",
"version": "v3.5.0", "version": "v3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation-contracts.git", "url": "https://github.com/symfony/translation-contracts.git",
"reference": "b9d2189887bb6b2e0367a9fc7136c5239ab9b05a" "reference": "4667ff3bd513750603a09c8dedbea942487fb07c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation-contracts/zipball/b9d2189887bb6b2e0367a9fc7136c5239ab9b05a", "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/4667ff3bd513750603a09c8dedbea942487fb07c",
"reference": "b9d2189887bb6b2e0367a9fc7136c5239ab9b05a", "reference": "4667ff3bd513750603a09c8dedbea942487fb07c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2887,7 +2969,7 @@
"standards" "standards"
], ],
"support": { "support": {
"source": "https://github.com/symfony/translation-contracts/tree/v3.5.0" "source": "https://github.com/symfony/translation-contracts/tree/v3.5.1"
}, },
"funding": [ "funding": [
{ {
@ -2903,7 +2985,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-04-18T09:32:20+00:00" "time": "2024-09-25T14:20:29+00:00"
}, },
{ {
"name": "twbs/bootstrap", "name": "twbs/bootstrap",
@ -2957,16 +3039,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.15.0", "version": "v3.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02" "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/2d5b3964cc21d0188633d7ddce732dc8e874db02", "url": "https://api.github.com/repos/twigphp/Twig/zipball/475ad2dc97d65d8631393e721e7e44fb544f0561",
"reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02", "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2977,6 +3059,7 @@
"symfony/polyfill-php81": "^1.29" "symfony/polyfill-php81": "^1.29"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^2.0",
"psr/container": "^1.0|^2.0", "psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0"
}, },
@ -3020,7 +3103,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.15.0" "source": "https://github.com/twigphp/Twig/tree/v3.16.0"
}, },
"funding": [ "funding": [
{ {
@ -3032,7 +3115,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-11-17T15:59:19+00:00" "time": "2024-11-29T08:27:05+00:00"
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
@ -3120,16 +3203,16 @@
}, },
{ {
"name": "voku/portable-ascii", "name": "voku/portable-ascii",
"version": "2.0.1", "version": "2.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/voku/portable-ascii.git", "url": "https://github.com/voku/portable-ascii.git",
"reference": "b56450eed252f6801410d810c8e1727224ae0743" "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/voku/portable-ascii/zipball/b56450eed252f6801410d810c8e1727224ae0743", "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b1d923f88091c6bf09699efcd7c8a1b1bfd7351d",
"reference": "b56450eed252f6801410d810c8e1727224ae0743", "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3154,7 +3237,7 @@
"authors": [ "authors": [
{ {
"name": "Lars Moelleken", "name": "Lars Moelleken",
"homepage": "http://www.moelleken.org/" "homepage": "https://www.moelleken.org/"
} }
], ],
"description": "Portable ASCII library - performance optimized (ascii) string functions for php.", "description": "Portable ASCII library - performance optimized (ascii) string functions for php.",
@ -3166,7 +3249,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/voku/portable-ascii/issues", "issues": "https://github.com/voku/portable-ascii/issues",
"source": "https://github.com/voku/portable-ascii/tree/2.0.1" "source": "https://github.com/voku/portable-ascii/tree/2.0.3"
}, },
"funding": [ "funding": [
{ {
@ -3190,7 +3273,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-03-08T17:03:00+00:00" "time": "2024-11-21T01:49:47+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],
@ -3205,5 +3288,5 @@
"ext-zip": "*" "ext-zip": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.3.0"
} }

279
kernel/EntityRelation.php Normal file
View File

@ -0,0 +1,279 @@
<?php
namespace kernel;
use Illuminate\Database\Eloquent\Model;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\option\service\OptionService;
use kernel\services\ModuleService;
class EntityRelation
{
protected ModuleService $moduleService;
public function __construct()
{
$this->moduleService = new ModuleService();
}
public static function getEntityList(): array
{
$list = [];
$moduleService = new ModuleService();
$activeModules = $moduleService->getActiveModules();
foreach ($activeModules as $module) {
if (isset($module['type']) and $module['type'] === "entity") {
$list[$module['slug']] = $module['slug'];
}
}
return $list;
}
public function getAdditionalPropertyList(): array
{
$list = [];
$activeModules = $this->moduleService->getActiveModules();
foreach ($activeModules as $module) {
if (isset($module['type']) and $module['type'] === "additional_property") {
$list[] = $module['slug'];
}
}
return $list;
}
public static function getEntitiesRelations(): array|bool
{
$entity_relations = OptionService::getItem("entity_relations");
if ($entity_relations) {
return json_decode($entity_relations, true);
}
return false;
}
public static function removePropertyFromEntityRelations(string $entity, string $property): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
if ($entity_relations[$entity]) {
$propertyKey = array_search($property, $entity_relations[$entity]);
if ($entity_relations[$entity][$propertyKey] === $property) {
unset($entity_relations[$entity][$propertyKey]);
$entity_relations[$entity] = array_values($entity_relations[$entity]);
if (empty($entity_relations[$entity])) {
unset($entity_relations[$entity]);
}
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
}
}
}
return false;
}
public static function removePropertyRelation(string $property): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
foreach ($entity_relations as $entity => $entity_relation) {
if (in_array($property, $entity_relation)) {
$index = array_search($property, $entity_relation);
unset($entity_relations[$entity][$index]);
}
}
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
}
return false;
}
public static function removeEntityRelation(string $entity): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
if (isset($entity_relations[$entity])) {
unset($entity_relations[$entity]);
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
}
}
return false;
}
public function getEntityRelationsBySlug(string $slug)
{
$entityRelations = $this->getEntitiesRelations();
if ($entityRelations) {
if (isset($entityRelations[$slug])) {
return $entityRelations[$slug];
}
}
return [];
}
public static function addEntityRelation(string $entity, string $property): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
if (isset($entity_relations[$entity])) {
$entity_relations[$entity][] = $property;
} else {
$entity_relations[$entity][] = $property;
}
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
}
return false;
}
public function getAdditionalPropertyClassBySlug(string $slug)
{
$module = $this->moduleService->getModuleInfoBySlug($slug);
if (isset($module['module_class'])) {
return new $module['module_class']();
}
return false;
}
public function renderFormInputsBySlug(string $entity, string $slug, Model $model): void
{
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
if ($moduleClass and method_exists($moduleClass, "formInputs")) {
$moduleClass->formInputs($entity, $model);
}
}
public function renderEntityAdditionalPropertyFormBySlug(string $entity, Model $model = null): void
{
$relations = $this->getEntityRelationsBySlug($entity);
if ($relations) {
foreach ($relations as $relation) {
$this->renderFormInputsBySlug($entity, $relation, $model);
}
}
}
public function saveEntityRelationBySlug(string $slug, string $entity, Model $model, Request $request): void
{
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
if ($moduleClass and method_exists($moduleClass, "saveInputs")) {
$moduleClass->saveInputs($entity, $model, $request);
}
}
public function saveEntityRelation(string $entity, Model $model, Request $request): void
{
$relations = $this->getEntityRelationsBySlug($entity);
if ($relations) {
foreach ($relations as $relation) {
$this->saveEntityRelationBySlug($relation, $entity, $model, $request);
}
}
}
public function getEntityAdditionalProperty(string $entity, Model $model): array
{
$relations = $this->getEntityRelationsBySlug($entity);
if ($relations) {
$relationsArr = [];
foreach ($relations as $relation) {
$moduleClass = $this->getAdditionalPropertyClassBySlug($relation);
if ($moduleClass and method_exists($moduleClass, "getItems")) {
$relationsArr[$relation] = $moduleClass->getItems($entity, $model);
}
}
return $relationsArr;
}
return [];
}
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug): string
{
$moduleClass = $this->getAdditionalPropertyClassBySlug($additionalPropertySlug);
if ($moduleClass and method_exists($moduleClass, "getItem")) {
return $moduleClass->getItem($entity, $entity_id);
}
return "";
}
public function deleteEntityRelationBySlug(string $slug, string $entity, Model $model): void
{
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
if ($moduleClass and method_exists($moduleClass, "deleteItems")) {
$moduleClass->deleteItems($entity, $model);
}
}
public function deleteEntityRelation(string $entity, Model $model): void
{
$relations = $this->getEntityRelationsBySlug($entity);
if ($relations) {
foreach ($relations as $relation) {
$this->deleteEntityRelationBySlug($relation, $entity, $model);
}
}
}
public static function getEntityByProperty(string $data): array
{
$entityRelations = self::getEntitiesRelations();
$entities = [];
foreach ($entityRelations as $entity => $property) {
if (in_array($data, $property)) {
$entities[] = $entity;
}
}
return $entities;
}
public static function configurationEntitiesByProperty(array|null $entities, string $property): void
{
$entityRelations = self::getEntitiesRelations();
if (isset($entities)) {
foreach ($entities as $entity) {
if (!isset($entityRelations[$entity])) {
EntityRelation::addEntityRelation($entity, $property);
}
}
foreach ($entityRelations as $entity => $additionalProperty) {
if (in_array($entity, $entities)) {
if (!in_array($property, $additionalProperty)) {
EntityRelation::addEntityRelation($entity, $property);
}
} else {
if (in_array($property, $additionalProperty)) {
EntityRelation::removePropertyFromEntityRelations($entity, $property);
}
}
}
} else {
foreach ($entityRelations as $entity => $additionalProperty) {
EntityRelation::removePropertyFromEntityRelations($entity, $property);
}
}
}
}

View File

@ -59,6 +59,16 @@ class FormModel
return false; return false;
} }
public function validateForUpdate(): bool
{
$res = $this->validator->validate($this->data, $this->rulesForUpdate());
if (!$res) {
return true;
}
return false;
}
public function getErrors(): array public function getErrors(): array
{ {
return $this->validator->getProcessedErrors(); return $this->validator->getProcessedErrors();

50
kernel/Mailing.php Normal file
View File

@ -0,0 +1,50 @@
<?php
namespace kernel;
use kernel\helpers\Debug;
use kernel\helpers\SMTP;
use PHPMailer\PHPMailer\Exception;
class Mailing
{
protected SMTP $SMTP;
protected CgView $cgView;
protected array $data;
public function __construct(array $data = [])
{
$this->cgView = new CgView();
$this->cgView->viewPath = KERNEL_DIR . "/views/mailing/";
$this->data = $data;
$this->SMTP = new SMTP();
$this->init();
}
/**
* @throws Exception
*/
public function send_html(string $tpl, array $tplParams, array $mailParams): ?false
{
$mailParams['body'] = $this->cgView->fetch($tpl, $tplParams);
return $this->SMTP->send_html($mailParams);
}
public function run()
{
}
public static function create(array $data = []): static
{
return new static($data);
}
protected function init()
{
}
}

View File

@ -11,7 +11,7 @@ class Widget
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
$this->cgView = new CgView(); $this->cgView = new CgView();
$this->cgView->viewPath = ROOT_DIR . "/views/widgets"; $this->cgView->viewPath = KERNEL_DIR . "/views/widgets";
$this->data = $data; $this->data = $data;

View File

@ -13,7 +13,7 @@
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<link rel="stylesheet" href="<?=$resources?>/css/style.css"> <link rel="stylesheet" href="<?=$resources?>/css/style.css">
</head> </head>
<body> <body>

View File

@ -46,6 +46,9 @@ class AdminConsoleController extends ConsoleController
$out = $this->migrationService->runAtPath("kernel/modules/post/migrations"); $out = $this->migrationService->runAtPath("kernel/modules/post/migrations");
$this->out->r("create post table", "green"); $this->out->r("create post table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/secure/migrations");
$this->out->r("create secret_code table", "green");
$this->optionService->createFromParams( $this->optionService->createFromParams(
key: "admin_theme_paths", key: "admin_theme_paths",
value: "{\"paths\": [\"{KERNEL_ADMIN_THEMES}\", \"{APP}/admin_themes\"]}", value: "{\"paths\": [\"{KERNEL_ADMIN_THEMES}\", \"{APP}/admin_themes\"]}",
@ -69,11 +72,18 @@ class AdminConsoleController extends ConsoleController
$this->optionService->createFromParams( $this->optionService->createFromParams(
key: "active_modules", key: "active_modules",
value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\", \"menu\"]}", value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\", \"menu\", \"post\", \"option\"]}",
label: "Активные модули" label: "Активные модули"
); );
$this->out->r("create option active_modules", "green"); $this->out->r("create option active_modules", "green");
$this->optionService->createFromParams(
key: "entity_relations",
value: "{}",
label: "Свойства сущностей"
);
$this->out->r("create option entity_relations", "green");
$this->menuService->createItem([ $this->menuService->createItem([
"label" => "Модули", "label" => "Модули",
"url" => "/admin", "url" => "/admin",
@ -101,6 +111,13 @@ class AdminConsoleController extends ConsoleController
]); ]);
$this->out->r("create item menu user", "green"); $this->out->r("create item menu user", "green");
$this->menuService->createItem([
"label" => "Посты",
"url" => "/admin/post",
"slug" => "post",
]);
$this->out->r("create item menu post", "green");
$this->menuService->createItem([ $this->menuService->createItem([
"label" => "Настройки", "label" => "Настройки",
"url" => "#", "url" => "#",
@ -116,6 +133,21 @@ class AdminConsoleController extends ConsoleController
]); ]);
$this->out->r("create item menu admin-themes", "green"); $this->out->r("create item menu admin-themes", "green");
$this->menuService->createItem([
"label" => "Меню",
"url" => "/admin/settings/menu",
"slug" => "menu",
"parent_slug" => "settings"
]);
$this->out->r("create item menu menu", "green");
$this->menuService->createItem([
"label" => "Опции",
"url" => "/admin/option",
"slug" => "option"
]);
$this->out->r("create item menu option", "green");
$user = new CreateUserForm(); $user = new CreateUserForm();
$user->load([ $user->load([
'username' => 'admin', 'username' => 'admin',

View File

@ -6,6 +6,7 @@ use DirectoryIterator;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Facades\Session; use Josantonius\Session\Facades\Session;
use kernel\AdminController; use kernel\AdminController;
use kernel\EntityRelation;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\models\Option; use kernel\models\Option;
use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\modules\module_shop_client\services\ModuleShopClientService;

42
kernel/helpers/Html.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace kernel\helpers;
class Html
{
public static function img(string $src, array $params = [])
{
$paramsStr = self::createParams($params);
return "<img src='$src' $paramsStr>";
}
public static function h(string|int $type = 1, string $title = '', array $params = [])
{
$paramsStr = self::createParams($params);
return "<h$type $paramsStr>$title</h$type>";
}
public static function a(string $link, array $params = []): string
{
$paramsStr = self::createParams($params);
return "<a href='$link' $paramsStr>";
}
/**
* @param array $data
* @return string
*/
public static function createParams(array $data = []): string
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}
return $paramsString;
}
}

View File

@ -22,4 +22,31 @@ class RESTClient
]); ]);
} }
/**
* @throws GuzzleException
*/
public static function request_without_auth(string $url, string $method = 'GET'): \Psr\Http\Message\ResponseInterface
{
$client = new \GuzzleHttp\Client();
return $client->request($method, $url);
}
/**
* @throws GuzzleException
*/
public static function post(string $url, array $data = [], bool $auth = true): \Psr\Http\Message\ResponseInterface
{
$headers = [];
if ($auth){
$headers = [
'Authorization' => 'Bearer ' . $_ENV['MODULE_SHOP_TOKEN']
];
}
$client = new \GuzzleHttp\Client();
return $client->request("POST", $url, [
'form_params' => $data,
'headers' => $headers,
]);
}
} }

40
kernel/helpers/SMTP.php Normal file
View File

@ -0,0 +1,40 @@
<?php
namespace kernel\helpers;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
class SMTP
{
public PHPMailer $mail;
public function __construct()
{
$this->mail = new PHPMailer(true);
$this->mail->CharSet = 'UTF-8';
$this->mail->isSMTP();
$this->mail->SMTPAuth = true;
$this->mail->SMTPDebug = 0;
$this->mail->Host = $_ENV['MAIL_SMTP_HOST'];
$this->mail->Port = $_ENV['MAIL_SMTP_PORT'];
$this->mail->Username = $_ENV['MAIL_SMTP_USERNAME'];
$this->mail->Password = $_ENV['MAIL_SMTP_PASSWORD'];
}
/**
* @throws Exception
*/
public function send_html(array $params)
{
if (!isset($params['address'])){
return false;
}
$this->mail->setFrom($this->mail->Username, $params['from_name'] ?? $this->mail->Host);
$this->mail->addAddress($params['address']);
$this->mail->Subject = $params['subject'] ?? 'Без темы';
$body = $params['body'] ?? 'Нет информации';
$this->mail->msgHTML($body);
$this->mail->send();
}
}

View File

@ -3,8 +3,6 @@
* @var $json string * @var $json string
*/ */
use kernel\models\Option;
$table = new \Itguild\Tables\ListJsonTable($json); $table = new \Itguild\Tables\ListJsonTable($json);
$table->columns([ $table->columns([
@ -13,14 +11,15 @@ $table->columns([
} }
]); ]);
$table->addAction(function ($row, $url){ $table->addAction(function ($row, $url){
$path = $row['path'];
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme'); $active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme');
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>";
if ($path === $active_admin_theme){
$btn = "Активна";
}
return $btn; if ($row['path'] === $active_admin_theme){
return "Активна";
} else {
$url = "$url/activate/?p=" . $row['path'];
return \kernel\widgets\IconBtn\IconBtnActivateWidget::create(['url' => $url])->run();
}
}); });
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -23,8 +23,7 @@ $table->rows([
} }
]); ]);
$table->beforePrint(function () { $table->beforePrint(function () {
$btn = PrimaryBtn::create("Список", "/admin/settings/admin-themes")->fetch(); return \kernel\widgets\IconBtn\IconBtnListWidget::create(['url' => '/admin/settings/admin-themes'])->run();
return $btn;
}); });
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -6,11 +6,11 @@
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu; use kernel\models\Menu;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -23,13 +23,22 @@ $table->columns([
if ($data == 0) return null; if ($data == 0) return null;
return Menu::find($data)->label; return Menu::find($data)->label;
}), }),
'icon_file' => function ($data) {
return $data ? "<img src='$data' width='150px'>" : "";
}
]); ]);
$table->beforePrint(function () { $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/settings/menu/create")->fetch(); return IconBtnCreateWidget::create(['url' => '/admin/settings/menu/create'])->run();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); });
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/settings/menu/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/settings/menu/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/settings/menu/delete/' . $row['id']])->run();
}); });
$table->addAction(ViewActionColumn::class);
$table->addAction(EditActionColumn::class);
$table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -6,10 +6,10 @@
use Itguild\EloquentTable\ViewEloquentTable; use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel; use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn;
use kernel\models\Menu; use kernel\models\Menu;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($menu, [ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($menu, [
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
@ -17,16 +17,19 @@ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($menu, [
])); ]));
$table->beforePrint(function () use ($menu) { $table->beforePrint(function () use ($menu) {
$btn = PrimaryBtn::create("Список", "/admin/settings/menu")->fetch(); $btn = IconBtnListWidget::create(['url' => '/admin/settings/menu'])->run();
$btn .= SuccessBtn::create("Редактировать", "/admin/settings/menu/update/" . $menu->id)->fetch(); $btn .= IconBtnEditWidget::create(['url' => '/admin/settings/menu/update/' . $menu->id])->run();
$btn .= DangerBtn::create("Удалить", "/admin/settings/menu/delete/" . $menu->id)->fetch(); $btn .= IconBtnDeleteWidget::create(['url' => '/admin/settings/menu/delete/' . $menu->id])->run();
return $btn; return $btn;
}); });
$table->rows([ $table->rows([
'parent_id' => (function ($data) { 'parent_id' => (function ($data) {
if ($data == 0) return null; if ($data == 0) return null;
return Menu::find($data)->label; return Menu::find($data)->label;
}) }),
'icon_file' => function ($data) {
return $data ? "<img src='$data' width='300px'>" : "";
}
]); ]);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -10,9 +10,14 @@ use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files; use kernel\helpers\Files;
use kernel\helpers\RESTClient; use kernel\helpers\RESTClient;
use kernel\helpers\SMTP;
use kernel\Mailing;
use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\Request; use kernel\Request;
use kernel\services\ModuleService; use kernel\services\ModuleService;
use kernel\services\ModuleShopService;
use kernel\services\TokenService;
use PHPMailer\PHPMailer\Exception;
class ModuleShopClientController extends AdminController class ModuleShopClientController extends AdminController
{ {
@ -34,18 +39,30 @@ class ModuleShopClientController extends AdminController
*/ */
public function actionIndex(int $page_number = 1): void public function actionIndex(int $page_number = 1): void
{ {
$per_page = 8;
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); if ($this->moduleService->issetModuleShopToken()) {
$modules_info = json_decode($modules_info->getBody()->getContents(), true); if ($this->moduleService->isServerAvailable()) {
$module_count = count($modules_info);
$modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page); $per_page = 8;
$this->cgView->render("index.php", [ $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
'modules_info' => $modules_info, $modules_info = json_decode($modules_info->getBody()->getContents(), true);
'moduleService' => $this->moduleService, $module_count = count($modules_info);
'page_number' => $page_number, $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page);
'module_count' => $module_count,
'per_page' => $per_page, $this->cgView->render("index.php", [
]); 'modules_info' => $modules_info,
'moduleService' => $this->moduleService,
'page_number' => $page_number,
'module_count' => $module_count,
'per_page' => $per_page,
]);
} else {
$this->cgView->render("module_shop_error_connection.php");
}
} else {
$this->cgView->render("login_at_module_shop.php");
}
} }
public function actionView(int $id): void public function actionView(int $id): void
@ -106,4 +123,58 @@ class ModuleShopClientController extends AdminController
$this->redirect('/admin/module_shop_client', 302); $this->redirect('/admin/module_shop_client', 302);
} }
/**
* @throws Exception
*/
public function actionAuth(): void
{
$request = new Request();
$address = $request->post("email");
// $mailing = new Mailing();
// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [
// 'address' => $address,
// 'subject' => "Код авторизации",
// "from_name" => $_ENV['APP_NAME']
// ]);
$moduleShopService = new ModuleShopService();
$result = $moduleShopService->email_auth($address);
if ($result['status'] == 'success'){
$this->cgView->render('enter_code.php', ['email' => $address]);
}
$this->cgView->render('module_shop_error_connection.php', ['email' => $address]);
}
public function actionCodeCheck(): void
{
$request = new Request();
$code = $request->post("code");
// $mailing = new Mailing();
// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [
// 'address' => $address,
// 'subject' => "Код авторизации",
// "from_name" => $_ENV['APP_NAME']
// ]);
$moduleShopService = new ModuleShopService();
$result = $moduleShopService->code_check($code);
if (isset($result['access_token'])){
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
$envFile->setValue("MODULE_SHOP_TOKEN", $result['access_token']);
$envFile->saveTo(ROOT_DIR . "/.env");
$this->cgView->render('success_login.php');
}
$this->cgView->render('module_shop_error_connection.php');
}
} }

View File

@ -15,6 +15,8 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']); App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']);
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']); App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']);
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']); App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']);
App::$collector->post('/auth', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAuth']);
App::$collector->post('/code_check', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionCodeCheck']);
}); });
}); });
}); });

View File

@ -0,0 +1,36 @@
<?php
/**
* @var $email
*/
use itguild\forms\ActiveForm;
\kernel\widgets\ModuleTabsWidget::create()->run();
echo \kernel\helpers\Html::h(2, "Введите код подтверждения отправленный на почту \"$email\"");
$form = new ActiveForm();
$form->beginForm("/admin/module_shop_client/code_check/");
$form->field(\itguild\forms\inputs\TextInput::class, 'code', [
'class' => "form-control",
'placeholder' => 'Код',
])
->setLabel("Код")
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -8,6 +8,7 @@
*/ */
use Itguild\Tables\ListJsonTable; use Itguild\Tables\ListJsonTable;
use kernel\widgets\ActionButtonWidget;
$meta = []; $meta = [];
$meta['columns'] = [ $meta['columns'] = [
@ -29,40 +30,39 @@ $info_to_table['data'] = $modules_info;
$table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); $table->addAction(function ($row, $url) use ($moduleService) {
$url = "$url/view/" . $row['id'];
return \kernel\widgets\IconBtn\IconBtnViewWidget::create(['url' => $url])->run();
});
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; if ($moduleService->isInstall($row['slug'])){
$id = $row['id']; $url = "$url/delete/?slug=" . $row['slug'];
if ($moduleService->isInstall($slug)){
$label = "Удалить"; return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
$btn_type = "danger";
$btn = "<a class='btn btn-$btn_type' href='$url/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
} }
else { else {
$label = "Установить"; $url = "$url/install/?id=" . $row['id'];
$btn_type = "success";
$btn = "<a class='btn btn-$btn_type' href='$url/install/?id=$id' style='margin: 3px; width: 150px;' >$label</a>";
}
return $btn; return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
if ($moduleService->isInstall($slug)){ if ($moduleService->isInstall($slug)){
if (!$moduleService->isLastVersion($slug)) { if (!$moduleService->isLastVersion($slug)) {
$label = "Обновить"; $url = "$url/update/?slug=" . $slug;
$btn_type = "info";
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
} }
} }
return false; return false;
}); });
\kernel\widgets\ModuleTabsWidget::create()->run();
$table->create(); $table->create();
\kernel\widgets\ModuleTabsWidget::create()->run();
$table->render(); $table->render();

View File

@ -0,0 +1,34 @@
<?php
use itguild\forms\ActiveForm;
\kernel\widgets\ModuleTabsWidget::create()->run();
echo \kernel\helpers\Html::h(2, "Форма авторизации/регистрации");
$form = new ActiveForm();
$form->beginForm("/admin/module_shop_client/auth/");
$form->field(\itguild\forms\inputs\TextInput::class, 'email', [
'class' => "form-control",
'placeholder' => 'Email',
])
->setLabel("Email")
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -0,0 +1,6 @@
<?php
\kernel\widgets\ModuleTabsWidget::create()->run();
?>
<h1>Ошибка подключения к сервису</h1>

View File

@ -0,0 +1,9 @@
<?php
use itguild\forms\ActiveForm;
\kernel\widgets\ModuleTabsWidget::create()->run();
echo \kernel\helpers\Html::h(2, "Авторизация прошла успешно");
echo \kernel\helpers\Html::a("/admin", ['class' => 'btm btm-primary']);

View File

@ -25,8 +25,7 @@ $table_info = [
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->beforePrint(function () { $table->beforePrint(function () {
$btn = PrimaryBtn::create("Список", "/admin/module_shop_client")->fetch(); return \kernel\widgets\IconBtn\IconBtnListWidget::create(['url' => '/admin/module_shop_client'])->run();
return $btn;
}); });
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -35,7 +35,7 @@ class OptionService
return false; return false;
} }
public function createFromParams(string $key, string $value, string $label): false|Option public static function createFromParams(string $key, string $value, string $label): false|Option
{ {
$model = new Option(); $model = new Option();
$model->key = $key; $model->key = $key;
@ -63,6 +63,17 @@ class OptionService
return false; return false;
} }
public static function removeOptionByKey(string $key): bool
{
$option = Option::where("key", $key)->first();
if (!$option){
return false;
}
$option->delete();
return true;
}
// public function createOptionArr(): array // public function createOptionArr(): array
// { // {
// foreach (Option::all()->toArray() as $option) { // foreach (Option::all()->toArray() as $option) {

View File

@ -11,6 +11,10 @@ use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn; use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\option\models\Option; use kernel\modules\option\models\Option;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(Option::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Option::class, [
'current_page' => $page_number, 'current_page' => $page_number,
@ -20,8 +24,7 @@ $table = new ListEloquentTable(new EloquentDataProvider(Option::class, [
])); ]));
$table->beforePrint(function () { $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/option/create")->fetch(); return IconBtnCreateWidget::create(['url' => '/admin/option/create'])->run();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
}); });
$table->columns([ $table->columns([
@ -31,8 +34,15 @@ $table->columns([
}] }]
]); ]);
$table->addAction(ViewActionColumn::class); $table->addAction(function($row) {
$table->addAction(EditActionColumn::class); return IconBtnViewWidget::create(['url' => '/admin/option/view/' . $row['id']])->run();
$table->addAction(DeleteActionColumn::class); });
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/option/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/option/delete/' . $row['id']])->run();
});
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -8,15 +8,18 @@ use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn; use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn; use kernel\IGTabel\btn\SuccessBtn;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($option, [ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($option, [
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user", 'baseUrl' => "/admin/user",
])); ]));
$table->beforePrint(function () use ($option) { $table->beforePrint(function () use ($option) {
$btn = PrimaryBtn::create("Список", "/admin/option")->fetch(); $btn = IconBtnListWidget::create(['url' => '/admin/option'])->run();
$btn .= SuccessBtn::create("Редактировать", "/admin/option/update/" . $option->id)->fetch(); $btn .= IconBtnEditWidget::create(['url' => '/admin/option/update/' . $option->id])->run();
$btn .= DangerBtn::create("Удалить", "/admin/option/delete/" . $option->id)->fetch(); $btn .= IconBtnDeleteWidget::create(['url' => '/admin/option/delete/' . $option->id])->run();
return $btn; return $btn;
}); });

View File

@ -6,9 +6,12 @@ namespace kernel\modules\post\controllers;
use Exception; use Exception;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController; use kernel\AdminController;
use kernel\EntityRelation;
use kernel\helpers\Debug;
use kernel\modules\post\models\forms\CreatePostForm; use kernel\modules\post\models\forms\CreatePostForm;
use kernel\modules\post\models\Post; use kernel\modules\post\models\Post;
use kernel\modules\post\service\PostService; use kernel\modules\post\service\PostService;
use kernel\Request;
class PostController extends AdminController class PostController extends AdminController
{ {
@ -31,6 +34,10 @@ class PostController extends AdminController
$postForm->load($_REQUEST); $postForm->load($_REQUEST);
if ($postForm->validate()) { if ($postForm->validate()) {
$post = $this->postService->create($postForm); $post = $this->postService->create($postForm);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
if ($post) { if ($post) {
$this->redirect("/admin/post/view/" . $post->id); $this->redirect("/admin/post/view/" . $post->id);
} }
@ -86,6 +93,10 @@ class PostController extends AdminController
$postForm->load($_REQUEST); $postForm->load($_REQUEST);
if ($postForm->validate()) { if ($postForm->validate()) {
$post = $this->postService->update($postForm, $post); $post = $this->postService->update($postForm, $post);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
if ($post) { if ($post) {
$this->redirect("/admin/post/view/" . $post->id); $this->redirect("/admin/post/view/" . $post->id);
} }
@ -102,6 +113,10 @@ class PostController extends AdminController
if (!$post){ if (!$post){
throw new Exception(message: "The post not found"); throw new Exception(message: "The post not found");
} }
$entityRelation = new EntityRelation();
$entityRelation->deleteEntityRelation(entity: "post", model: $post);
$post->delete(); $post->delete();
$this->redirect("/admin/post/"); $this->redirect("/admin/post/");
} }

View File

@ -3,6 +3,7 @@
"version": "0.2", "version": "0.2",
"author": "ITGuild", "author": "ITGuild",
"slug": "post", "slug": "post",
"type": "entity",
"description": "Post module", "description": "Post module",
"module_class": "kernel\\modules\\post\\PostModule", "module_class": "kernel\\modules\\post\\PostModule",
"module_class_file": "{KERNEL_MODULES}/post/PostModule.php", "module_class_file": "{KERNEL_MODULES}/post/PostModule.php",

View File

@ -6,7 +6,7 @@
use kernel\modules\post\models\Post; use kernel\modules\post\models\Post;
$form = new \itguild\forms\ActiveForm(); $form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post"); $form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post", 'multipart/form-data');
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [ $form->field(\itguild\forms\inputs\TextInput::class, 'title', [
'class' => "form-control", 'class' => "form-control",
@ -33,6 +33,12 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr()) ->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
->render(); ->render();
$entityRelations = new \kernel\EntityRelation();
if (!isset($model)) {
$model = new Post();
}
$entityRelations->renderEntityAdditionalPropertyFormBySlug("post", $model);
?> ?>
<div class="row"> <div class="row">
<div class="col-sm-2"> <div class="col-sm-2">

View File

@ -13,6 +13,10 @@ use kernel\modules\user\models\User;
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -20,6 +24,16 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/post" 'baseUrl' => "/admin/post"
])); ]));
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityRelationsBySlug("post");
foreach ($additionals as $additional) {
$table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) {
return $entityRelation->getAdditionalPropertyByEntityId("post", $id, $additional);
});
}
$table->columns([ $table->columns([
'created_at' => function ($data) { 'created_at' => function ($data) {
if (!$data){ if (!$data){
@ -39,12 +53,18 @@ $table->columns([
return User::find($data)->username; return User::find($data)->username;
}) })
]); ]);
$table->beforePrint(function () { $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch(); return IconBtnCreateWidget::create(['url' => '/admin/post/create'])->run();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); });
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/post/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/post/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $row['id']])->run();
}); });
$table->addAction(ViewActionColumn::class);
$table->addAction(EditActionColumn::class);
$table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -10,26 +10,39 @@ use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn; use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn; use kernel\IGTabel\btn\SuccessBtn;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/post", 'baseUrl' => "/admin/post",
])); ]));
$table->beforePrint(function () use ($content) { $table->beforePrint(function () use ($content) {
$btn = PrimaryBtn::create("Список", "/admin/post")->fetch(); $btn = IconBtnListWidget::create(['url' => '/admin/post'])->run();
$btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch(); $btn .= IconBtnEditWidget::create(['url' => '/admin/post/update/' . $content->id])->run();
$btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch(); $btn .= IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $content->id])->run();
return $btn; return $btn;
}); });
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityAdditionalProperty("post", $content);
foreach ($additionals as $key => $additional) {
$table->addRow($key, function () use ($additional) {
return $additional;
}, ['after' => 'user_id']);
}
$table->rows([ $table->rows([
'created_at' => function ($data) { 'created_at' => function ($data) {
if (!$data){ if (!$data) {
return null; return null;
} }
return (new DateTimeImmutable($data))->format("d-m-Y"); return (new DateTimeImmutable($data))->format("d-m-Y");
}, },
'updated_at' => function ($data) { 'updated_at' => function ($data) {
if (!$data){ if (!$data) {
return null; return null;
} }
return (new DateTimeImmutable($data))->format("d-m-Y"); return (new DateTimeImmutable($data))->format("d-m-Y");

View File

@ -4,10 +4,19 @@ namespace kernel\modules\secure\controllers;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController; use kernel\AdminController;
use kernel\App;
use kernel\Flash; use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\Mailing;
use kernel\modules\secure\models\forms\LoginEmailForm;
use kernel\modules\secure\models\forms\LoginForm; use kernel\modules\secure\models\forms\LoginForm;
use kernel\modules\secure\models\forms\RegisterForm;
use kernel\modules\secure\services\SecureService;
use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService; use kernel\modules\user\service\UserService;
use kernel\Request;
use PHPMailer\PHPMailer\Exception;
use Random\RandomException;
class SecureController extends AdminController class SecureController extends AdminController
{ {
@ -16,7 +25,6 @@ class SecureController extends AdminController
protected function init(): void protected function init(): void
{ {
parent::init(); parent::init();
// $this->cgView->viewPath = KERNEL_DIR . "/views/secure/";
$this->cgView->viewPath = KERNEL_MODULES_DIR. "/secure/views/"; $this->cgView->viewPath = KERNEL_MODULES_DIR. "/secure/views/";
$this->cgView->layout = "/login.php"; $this->cgView->layout = "/login.php";
$this->userService = new UserService(); $this->userService = new UserService();
@ -24,7 +32,12 @@ class SecureController extends AdminController
public function actionLogin(): void public function actionLogin(): void
{ {
$this->cgView->render('login.php'); $this->cgView->render(match (App::$secure['web_auth_type']) {
"login_password" => "login.php",
"email_code" => "email_login.php",
});
// $this->cgView->render('login.php');
} }
#[NoReturn] public function actionAuth(): void #[NoReturn] public function actionAuth(): void
@ -44,8 +57,9 @@ class SecureController extends AdminController
Flash::setMessage("error", "User not found."); Flash::setMessage("error", "User not found.");
$this->redirect("/admin/login", code: 302); $this->redirect("/admin/login", code: 302);
} }
if (password_verify($loginForm->getItem("password"), $user->password_hash)) { if (password_verify($loginForm->getItem("password"), $user->password_hash)) {
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['HTTP_HOST'], false); setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
$this->redirect("/admin", code: 302); $this->redirect("/admin", code: 302);
} else { } else {
Flash::setMessage("error", "Username or password incorrect."); Flash::setMessage("error", "Username or password incorrect.");
@ -53,11 +67,107 @@ class SecureController extends AdminController
} }
} }
/**
* @throws RandomException
* @throws Exception
*/
public function actionEmailAuth(): void
{
$mailing = new Mailing();
$loginForm = new LoginEmailForm();
$loginForm->load($_REQUEST);
$email = $loginForm->getItem("email");
$user = $this->userService->getByField('email', $email);
if (!$user){
$password = bin2hex(random_bytes(8));
UserService::createUserByEmailAndPassword($email, $password);
$user = $this->userService->getByField('email', $email);
SecureService::createSecretCode($user);
$secretCode = SecureService::getByField("user_id", $user->id);
$mailing->send_html("register_by_code.php", ['code' => $secretCode->code, 'password' => $password], [
'address' => $email,
'subject' => "Код регистрации",
"from_name" => $_ENV['APP_NAME']
]);
} else {
SecureService::updateSecretCode($user);
$secretCode = SecureService::getByField("user_id", $user->id);
$mailing->send_html("login_by_code.php", ['code' => $secretCode->code], [
'address' => $email,
'subject' => "Код авторизации",
"from_name" => $_ENV['APP_NAME']
]);
}
setcookie('user_email', $email, time()+60*15, '/', $_SERVER['SERVER_NAME'], false);
$this->cgView->render("enter_code.php", ['email' => $email]);
}
/**
* @throws Exception
*/
public function actionCodeCheck(): void
{
$request = new Request();
if (isset($_COOKIE['user_email'])) {
$user = User::where('email', $_COOKIE["user_email"])->first();
if (!$user) {
throw new exception("User not found.");
}
$code = $request->post("code");
$secretCode = SecureService::getByField("user_id", $user->id);
if ($secretCode->code == $code && time() <= strtotime($secretCode->code_expires_at)) {
setcookie('user_id', $user->id, time() + 60 * 60 * 24, '/', $_SERVER['SERVER_NAME'], false);
$this->redirect("/admin", code: 302);
} else {
Flash::setMessage("error", "Wrong code.");
$this->cgView->render("enter_code.php", ['email' => $_COOKIE["user_email"]]);
}
}
}
#[NoReturn] public function actionLogout(): void #[NoReturn] public function actionLogout(): void
{ {
unset($_COOKIE['user_id']); unset($_COOKIE['user_id']);
setcookie('user_id', "", -1, '/', ".".$_SERVER['SERVER_NAME'], false); setcookie('user_id', "", -1, '/', ".".$_SERVER['SERVER_NAME'], false);
setcookie('user_email', "", -1, '/', ".".$_SERVER['SERVER_NAME'], false);
$this->redirect("/", code: 302); $this->redirect("/", code: 302);
} }
public function actionRegister(): void
{
$this->cgView->render('register.php');
}
public function actionRegistration(): void
{
$regForm = new RegisterForm();
$regForm->load($_REQUEST);
if ($this->userService->getByField('username', $regForm->getItem("username"))) {
Flash::setMessage("error", "Username already exists.");
$this->redirect("/admin/register", code: 302);
}
if ($this->userService->getByField('email', $regForm->getItem("email"))) {
Flash::setMessage("error", "Email already exists.");
$this->redirect("/admin/register", code: 302);
}
$user = $this->userService->create($regForm);
if ($user){
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
$this->redirect("/admin", code: 302);
}
}
} }

View File

@ -7,10 +7,15 @@ use Firebase\JWT\Key;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use kernel\App; use kernel\App;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\Mailing;
use kernel\modules\secure\models\SecretCode;
use kernel\modules\secure\services\SecureService;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService;
use kernel\Request; use kernel\Request;
use kernel\RestController; use kernel\RestController;
use kernel\services\TokenService; use kernel\services\TokenService;
use PHPMailer\PHPMailer\Exception;
use Random\RandomException; use Random\RandomException;
class SecureRestController extends RestController class SecureRestController extends RestController
@ -51,4 +56,75 @@ class SecureRestController extends RestController
$this->renderApi($res); $this->renderApi($res);
} }
} /**
* @throws Exception
* @throws RandomException
*/
#[NoReturn] public function actionEmailAuth(): void
{
$mailing = new Mailing();
$request = new Request();
$data = $request->post();
$model = $this->model->where('email', $data['email'])->first();
if (!$model) {
$password = bin2hex(random_bytes(8));
UserService::createUserByEmailAndPassword($data['email'], $password);
$model = UserService::getByField('email', $data['email']);
SecureService::createSecretCode($model);
$secretCode = SecureService::getByField("user_id", $model->id);
$mailing->send_html("register_by_code.php", ['code' => $secretCode->code, 'password' => $password], [
'address' => $data['email'],
'subject' => "Код регистрации",
"from_name" => $_ENV['APP_NAME']
]);
} else {
SecureService::updateSecretCode($model);
$secretCode = SecureService::getByField("user_id", $model->id);
$mailing->send_html("login_by_code.php", ['code' => $secretCode->code], [
'address' => $data['email'],
'subject' => "Код авторизации",
"from_name" => $_ENV['APP_NAME']
]);
}
$res = [
"status" => "success",
"code_expires_at" => $secretCode->code_expires_at,
];
setcookie('user_email', $data['email'], time()+60*15, '/', $_SERVER['SERVER_NAME'], false);
$this->renderApi($res);
}
/**
* @throws Exception
*/
#[NoReturn] public function actionCodeCheck(): void
{
$request = new Request();
$code = $request->post("code");
$model = SecretCode::where("code", $code)->first();
if (time() <= strtotime($model->code_expires_at)) {
$user = $this->model->where("id", $model->user_id)->first();
if ($user){
$user->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time']));
$user->access_token = SecureService::generateAccessToken();
$user->save();
$this->renderApi([
"access_token" => $user->access_token,
"access_token_expires_at" => $user->access_token_expires_at,
]);
}
}
$this->renderApi(['status' => 'error', 'message' => 'incorrect code']);
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
\kernel\App::$db->schema->create('secret_code', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('code');
$table->dateTime('code_expires_at')->nullable(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('secret_code');
}
};

View File

@ -0,0 +1,25 @@
<?php
namespace kernel\modules\secure\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $user_id
* @property int $code
* @property string $code_expires_at
*/
class SecretCode extends Model {
protected $table = 'secret_code';
protected $fillable = ['user_id', 'code', 'code_expires_at'];
public static function labels(): array
{
return [
'user_id' => 'Пользователь',
'code' => 'Код',
'code_expires_at' => 'Срок жизни кода',
];
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace kernel\modules\secure\models\forms;
use kernel\FormModel;
class LoginEmailForm extends FormModel
{
public function rules(): array
{
return [
'email' => 'required|string|email|max255',
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace kernel\modules\secure\models\forms;
use kernel\FormModel;
class RegisterForm extends FormModel
{
public function rules(): array
{
return [
'username' => 'required|min-str-len:5|max-str-len:50',
'email' => 'required|email|max-str-len:50',
'password' => 'required|min-str-len:6|max-str-len:50',
];
}
}

View File

@ -14,11 +14,17 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']); App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']);
App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']); App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']);
App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']); App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']);
App::$collector->post('/email_auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionEmailAuth']);
App::$collector->get('/register', [\kernel\modules\secure\controllers\SecureController::class, 'actionRegister']);
App::$collector->post('/registration', [\kernel\modules\secure\controllers\SecureController::class, 'actionRegistration']);
App::$collector->post('/code_check', [\kernel\modules\secure\controllers\SecureController::class, 'actionCodeCheck']);
}); });
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){ App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
App::$collector->group(["prefix" => "secure"], function (CgRouteCollector $router) { App::$collector->group(["prefix" => "secure"], function (CgRouteCollector $router) {
App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureRestController::class, 'actionAuth']); App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureRestController::class, 'actionAuth']);
App::$collector->post('/email_auth', [\kernel\modules\secure\controllers\SecureRestController::class, 'actionEmailAuth']);
App::$collector->post('/code_check', [\kernel\modules\secure\controllers\SecureRestController::class, 'actionCodeCheck']);
}); });
}); });

View File

@ -0,0 +1,54 @@
<?php
namespace kernel\modules\secure\services;
use kernel\App;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\secure\models\SecretCode;
use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService;
use kernel\services\TokenService;
class SecureService
{
public static function createSecretCode(User $user): void
{
$secretCode = new SecretCode();
$secretCode->user_id = $user->id;
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
}
public static function updateSecretCode(User $user): void
{
$secretCode = SecretCode::where('user_id', $user->id)->first();
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
}
public static function getCodeByUserId(int $user_id)
{
return SecretCode::where('user_id', $user_id)->one()->code;
}
public static function getByField(string $field, mixed $value)
{
return SecretCode::where($field, $value)->first();
}
public static function generateAccessToken(): string
{
return match (App::$secure['token_type']) {
"JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'),
"md5" => TokenService::md5(),
"crypt" => TokenService::crypt(),
"hash" => TokenService::hash('sha256'),
default => TokenService::random_bytes(20),
};
}
}

View File

@ -0,0 +1,48 @@
<!-- Section: Design Block -->
<section class=" text-center text-lg-start">
<style>
.rounded-t-5 {
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
}
@media (min-width: 992px) {
.rounded-tr-lg-0 {
border-top-right-radius: 0;
}
.rounded-bl-lg-5 {
border-bottom-left-radius: 0.5rem;
}
}
</style>
<div class="card mb-3">
<div class="row g-0 d-flex align-items-center">
<div class="col-lg-4 d-none d-lg-flex">
<img src="https://mdbootstrap.com/img/new/ecommerce/vertical/004.jpg" alt="Trendy Pants and Shoes"
class="w-100 rounded-t-5 rounded-tr-lg-0 rounded-bl-lg-5" />
</div>
<div class="col-lg-8">
<div class="card-body py-5 px-md-5">
<div class="row md-4 text-md-center">
<h1>Форма авторизации/регистрации</h1>
</div>
<form action="/admin/email_auth" method="post">
<!-- Email input -->
<div data-mdb-input-init class="form-outline mb-4">
<input type="text" id="form2Example1" class="form-control" name="email" />
<label class="form-label" for="form2Example1">Email</label>
</div>
<!-- Submit button -->
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">Отправить</button>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- Section: Design Block -->

View File

@ -0,0 +1,60 @@
<?php
/**
* @var string $email
*/
?>
<!-- Section: Design Block -->
<section class=" text-center text-lg-start">
<style>
.rounded-t-5 {
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
}
@media (min-width: 992px) {
.rounded-tr-lg-0 {
border-top-right-radius: 0;
}
.rounded-bl-lg-5 {
border-bottom-left-radius: 0.5rem;
}
}
</style>
<div class="card mb-3">
<div class="row g-0 d-flex align-items-center">
<div class="col-lg-4 d-none d-lg-flex">
<img src="https://mdbootstrap.com/img/new/ecommerce/vertical/004.jpg" alt="Trendy Pants and Shoes"
class="w-100 rounded-t-5 rounded-tr-lg-0 rounded-bl-lg-5" />
</div>
<div class="col-lg-8">
<div class="card-body py-5 px-md-5">
<div class="row md-4 text-md-center">
<h1>Введите код, отправленный на почту "<?php echo $email ?>"</h1>
</div>
<form action="/admin/code_check" method="post">
<!-- Email input -->
<div data-mdb-input-init class="form-outline mb-4">
<input type="text" id="form2Example1" class="form-control" name="code" />
<label class="form-label" for="form2Example1">Код подтверждения</label>
</div>
<div class="row-md-4">
<div class="col">
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">Подтвердить</button>
</div>
<div class="col">
<br>
<a href="/admin/login/"> <h5>Отправить код еще раз</h5></a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- Section: Design Block -->

View File

@ -24,6 +24,9 @@
</div> </div>
<div class="col-lg-8"> <div class="col-lg-8">
<div class="card-body py-5 px-md-5"> <div class="card-body py-5 px-md-5">
<div class="row md-4 text-md-center">
<h1>Авторизация</h1>
</div>
<form action="/admin/auth" method="post"> <form action="/admin/auth" method="post">
<!-- Email input --> <!-- Email input -->
@ -48,10 +51,15 @@
</div> </div>
</div> </div>
<div class="col"> <div class="col-3">
<!-- Simple link --> <!-- Simple link -->
<a href="#!">Забыл пароль?</a> <a href="#!">Забыл пароль?</a>
</div> </div>
<div class="col">
<!-- Simple link -->
<a href="/admin/register">Регистрация</a>
</div>
</div> </div>
<!-- Submit button --> <!-- Submit button -->

View File

@ -0,0 +1,71 @@
<!-- Section: Design Block -->
<section class=" text-center text-lg-start">
<style>
.rounded-t-5 {
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
}
@media (min-width: 992px) {
.rounded-tr-lg-0 {
border-top-right-radius: 0;
}
.rounded-bl-lg-5 {
border-bottom-left-radius: 0.5rem;
}
}
</style>
<div class="card mb-3">
<div class="row g-0 d-flex align-items-center">
<div class="col-lg-4 d-none d-lg-flex">
<img src="https://mdbootstrap.com/img/new/ecommerce/vertical/004.jpg" alt="Trendy Pants and Shoes"
class="w-100 rounded-t-5 rounded-tr-lg-0 rounded-bl-lg-5" />
</div>
<div class="col-lg-8">
<div class="card-body py-5 px-md-5">
<div class="row md-4 text-md-center">
<h1>Регистрация</h1>
</div>
<form action="/admin/registration" method="post">
<!--Username input -->
<div data-mdb-input-init class="form-outline mb-4">
<input type="text" id="form2Example1" class="form-control" name="username" />
<label class="form-label" for="form2Example1">Логин</label>
</div>
<!-- Email input -->
<div data-mdb-input-init class="form-outline mb-4">
<input type="email" id="form2Example1" class="form-control" name="email" />
<label class="form-label" for="form2Example1">Email</label>
</div>
<!-- Password input -->
<div data-mdb-input-init class="form-outline mb-4">
<input type="password" id="form2Example2" class="form-control" name="password" />
<label class="form-label" for="form2Example2">Пароль</label>
</div>
<div class="row mb-4">
<div class="col-4">
<!-- Submit button -->
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">Регистрация</button>
</div>
<div class="col-4">
<!-- Simple link -->
<a href="/admin/login">Войти в существующий аккаунт</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- Section: Design Block -->

View File

@ -5,9 +5,11 @@ namespace kernel\modules\user\controllers;
use Exception; use Exception;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController; use kernel\AdminController;
use kernel\EntityRelation;
use kernel\modules\user\models\forms\CreateUserForm; use kernel\modules\user\models\forms\CreateUserForm;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService; use kernel\modules\user\service\UserService;
use kernel\Request;
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Error\RuntimeError; use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
@ -35,6 +37,11 @@ class UserController extends AdminController
$userForm->load($_REQUEST); $userForm->load($_REQUEST);
if ($userForm->validate()){ if ($userForm->validate()){
$user = $this->userService->create($userForm); $user = $this->userService->create($userForm);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){ if ($user){
$this->redirect("/admin/user/view/" . $user->id); $this->redirect("/admin/user/view/" . $user->id);
} }
@ -91,8 +98,12 @@ class UserController extends AdminController
$userForm = new CreateUserForm(); $userForm = new CreateUserForm();
$userService = new UserService(); $userService = new UserService();
$userForm->load($_REQUEST); $userForm->load($_REQUEST);
if ($userForm->validate()){ if ($userForm->validateForUpdate()){
$user = $userService->update($userForm, $user); $user = $userService->update($userForm, $user);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){ if ($user){
$this->redirect("/admin/user/view/" . $user->id); $this->redirect("/admin/user/view/" . $user->id);
} }
@ -100,9 +111,20 @@ class UserController extends AdminController
$this->redirect("/admin/user/update/" . $id); $this->redirect("/admin/user/update/" . $id);
} }
/**
* @throws Exception
*/
#[NoReturn] public function actionDelete($id): void #[NoReturn] public function actionDelete($id): void
{ {
User::find($id)->delete(); $user = User::find($id)->first();
if (!$user){
throw new Exception(message: "The user not found");
}
$entityRelation = new EntityRelation();
$entityRelation->deleteEntityRelation(entity: "user", model: $user);
$user->delete();
$this->redirect("/admin/user/"); $this->redirect("/admin/user/");
} }

View File

@ -3,6 +3,7 @@
"version": "0.1", "version": "0.1",
"author": "ITGuild", "author": "ITGuild",
"slug": "user", "slug": "user",
"type": "entity",
"description": "User module", "description": "User module",
"module_class": "kernel\\modules\\user\\UserModule", "module_class": "kernel\\modules\\user\\UserModule",
"module_class_file": "{KERNEL_MODULES}/user/UserModule.php", "module_class_file": "{KERNEL_MODULES}/user/UserModule.php",

View File

@ -16,4 +16,13 @@ class CreateUserForm extends FormModel
]; ];
} }
public function rulesForUpdate(): array
{
return [
'username' => 'required|min-str-len:5|max-str-len:30',
'password' => '',
'email' => 'required|email'
];
}
} }

View File

@ -3,6 +3,7 @@
namespace kernel\modules\user\service; namespace kernel\modules\user\service;
use kernel\FormModel; use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
class UserService class UserService
@ -25,7 +26,9 @@ class UserService
{ {
$user->username = $form_model->getItem('username'); $user->username = $form_model->getItem('username');
$user->email = $form_model->getItem('email'); $user->email = $form_model->getItem('email');
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT); if ($form_model->getItem('password')) {
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
}
if ($user->save()){ if ($user->save()){
return $user; return $user;
} }
@ -38,7 +41,7 @@ class UserService
* @param string $value * @param string $value
* @return mixed * @return mixed
*/ */
public function getByField(string $field, string $value) public static function getByField(string $field, string $value): mixed
{ {
return User::where($field, $value)->first(); return User::where($field, $value)->first();
} }
@ -82,4 +85,13 @@ class UserService
return $this->getByField("access_token", $token); return $this->getByField("access_token", $token);
} }
public static function createUserByEmailAndPassword(string $email, string $password): void
{
$user = new User();
$user->email = $email;
$user->username = $email;
$user->password_hash = password_hash($password, PASSWORD_DEFAULT);
$user->save();
}
} }

View File

@ -6,7 +6,7 @@
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
$form = new \itguild\forms\ActiveForm(); $form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/user/edit/" . $model->id : "/admin/user"); $form->beginForm(isset($model) ? "/admin/user/edit/" . $model->id : "/admin/user", enctype: 'multipart/form-data');
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [
'class' => "form-control", 'class' => "form-control",
@ -32,6 +32,11 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", param
->setLabel("Email") ->setLabel("Email")
->render(); ->render();
$entityRelations = new \kernel\EntityRelation();
if (!isset($model)) {
$model = new User();
}
$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model);
?> ?>
<div class="row"> <div class="row">
<div class="col-sm-2"> <div class="col-sm-2">

View File

@ -12,6 +12,10 @@ use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn; use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [ $table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -20,6 +24,16 @@ $table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'baseUrl' => "/admin/user", 'baseUrl' => "/admin/user",
'filters' => ['email'], 'filters' => ['email'],
])); ]));
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityRelationsBySlug("user");
foreach ($additionals as $additional) {
$table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) {
return $entityRelation->getAdditionalPropertyByEntityId("user", $id, $additional);
});
}
$table->columns([ $table->columns([
'username' => [ 'username' => [
"filter" => [ "filter" => [
@ -42,11 +56,16 @@ $table->columns([
} }
]); ]);
$table->beforePrint(function () { $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch(); return IconBtnCreateWidget::create(['url' => '/admin/user/create'])->run();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); });
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/user/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/user/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/user/delete/' . $row['id']])->run();
}); });
$table->addAction(ViewActionColumn::class);
$table->addAction(EditActionColumn::class);
$table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -10,17 +10,30 @@ use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn; use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn; use kernel\IGTabel\btn\SuccessBtn;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [
'params' => ["class" => "table table-bordered", "border" => "2"], 'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user", 'baseUrl' => "/admin/user",
])); ]));
$table->beforePrint(function () use ($user) { $table->beforePrint(function () use ($user) {
$btn = PrimaryBtn::create("Список", "/admin/user")->fetch(); $btn = IconBtnListWidget::create(['url' => '/admin/user'])->run();
$btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch(); $btn .= IconBtnEditWidget::create(['url' => '/admin/user/update/' . $user->id])->run();
$btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch(); $btn .= IconBtnDeleteWidget::create(['url' => '/admin/user/delete/' . $user->id])->run();
return $btn; return $btn;
}); });
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityAdditionalProperty("user", $user);
foreach ($additionals as $key => $additional) {
$table->addRow($key, function () use ($additional) {
return $additional;
}, ['after' => 'email']);
}
$table->rows([ $table->rows([
'created_at' => function ($data) { 'created_at' => function ($data) {
if (!$data){ if (!$data){

View File

@ -23,6 +23,7 @@ class MigrationService
public function runAtPath(string $path = ROOT_DIR . '/migrations'): array public function runAtPath(string $path = ROOT_DIR . '/migrations'): array
{ {
$path = getConst($path); $path = getConst($path);
// Debug::dd($path);
try { try {
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration'); $dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
@ -31,7 +32,7 @@ class MigrationService
return $m->run($path); return $m->run($path);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new \Exception('Не удалось поднять играции'); throw new \Exception('Не удалось поднять миграции');
} }
} }

View File

@ -3,18 +3,22 @@
namespace kernel\services; namespace kernel\services;
use DirectoryIterator; use DirectoryIterator;
use GuzzleHttp\Client; use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files; use kernel\helpers\Files;
use kernel\helpers\Manifest; use kernel\helpers\Manifest;
use kernel\helpers\RESTClient; use kernel\helpers\RESTClient;
use kernel\models\Option; use kernel\models\Option;
use MongoDB\Driver\Session;
use ZipArchive; use ZipArchive;
class ModuleService class ModuleService
{ {
protected array $errors = []; protected array $errors = [];
protected null|bool $serverAvailable = null;
/** /**
* @param string $module * @param string $module
* @return false|array|string * @return false|array|string
@ -67,9 +71,9 @@ class ModuleService
{ {
$active_modules = Option::where("key", "active_modules")->first(); $active_modules = Option::where("key", "active_modules")->first();
if ($active_modules) { if ($active_modules) {
$path = json_decode($active_modules->value); $modules = json_decode($active_modules->value);
foreach ($path->modules as $p) { foreach ($modules->modules as $mod) {
if ($p === $slug) { if ($mod === $slug) {
return true; return true;
} }
} }
@ -109,7 +113,7 @@ class ModuleService
if (isset($module_info['dependence'])) { if (isset($module_info['dependence'])) {
$dependence_array = explode(',', $module_info['dependence']); $dependence_array = explode(',', $module_info['dependence']);
foreach ($dependence_array as $depend) { foreach ($dependence_array as $depend) {
if (!in_array($depend, $active_modules->modules)) { if (!in_array(trim($depend), $active_modules->modules)) {
$this->addError("first activate the $depend module"); $this->addError("first activate the $depend module");
return false; return false;
} }
@ -131,6 +135,10 @@ class ModuleService
public function deactivateModule(string $module): bool public function deactivateModule(string $module): bool
{ {
$active_modules_info = Option::where("key", "active_modules")->first(); $active_modules_info = Option::where("key", "active_modules")->first();
EntityRelation::removeEntityRelation($module);
EntityRelation::removePropertyRelation($module);
$active_modules = json_decode($active_modules_info->value); $active_modules = json_decode($active_modules_info->value);
if (!in_array($module, $active_modules->modules)) { if (!in_array($module, $active_modules->modules)) {
return true; return true;
@ -355,8 +363,6 @@ class ModuleService
mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true); mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
} }
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm'); $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm');
//$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
} }
/** /**
@ -438,17 +444,19 @@ class ModuleService
public function isLastVersion(string $slug): bool public function isLastVersion(string $slug): bool
{ {
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true); $modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug); $mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) { foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
return true; return true;
}
} }
} }
return false;
return false;
} }
public function isKernelModule(string $slug): bool public function isKernelModule(string $slug): bool
@ -463,6 +471,27 @@ class ModuleService
return false; return false;
} }
public function isShopModule(string $slug): bool
{
if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
if (!$this->issetModuleShopToken()){
return false;
}
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug']) {
return true;
}
}
}
return false;
}
public function getKernelModules(): array public function getKernelModules(): array
{ {
$modules_info = []; $modules_info = [];
@ -474,4 +503,30 @@ class ModuleService
return $modules_info; return $modules_info;
} }
public function isServerAvailable(): bool
{
if (null !== $this->serverAvailable){
return $this->serverAvailable;
}
try {
RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$this->serverAvailable = true;
return true;
} catch (\Exception $e) {
$this->serverAvailable = false;
return false;
}
}
public function issetModuleShopToken(): bool
{
if (!empty($_ENV['MODULE_SHOP_TOKEN'])){
return true;
}
return false;
}
} }

View File

@ -0,0 +1,36 @@
<?php
namespace kernel\services;
use GuzzleHttp\Exception\GuzzleException;
use kernel\helpers\RESTClient;
class ModuleShopService
{
protected string $url;
protected string $token;
public function __construct()
{
$this->url = $_ENV['MODULE_SHOP_URL'];
$this->token = $_ENV['MODULE_SHOP_TOKEN'];
}
/**
* @throws GuzzleException
*/
public function email_auth(string $email)
{
$request = RESTClient::post($this->url . "/api/secure/email_auth", ['email' => $email], false);
return json_decode($request->getBody()->getContents(), true);
}
public function code_check(string $code)
{
$request = RESTClient::post($this->url . "/api/secure/code_check", ['code' => $code], false);
return json_decode($request->getBody()->getContents(), true);
}
}

View File

@ -0,0 +1,12 @@
<?php
/**
* @var int $code
*/
?>
<p>
Код подтверждения: <?= $code ?>
</p>
<p>
Если вы не запрашивали код, проигнорируйте данное письмо.
</p>

View File

@ -0,0 +1,15 @@
<?php
/**
* @var int $code
* @var string $password
*/
?>
<p>
Код подтверждения: <?= $code ?> <br><br>
Ваш пароль: <?= $password ?>
</p>
<p>
Если вы не запрашивали код, проигнорируйте данное письмо.
</p>

View File

@ -7,6 +7,14 @@
* @var \kernel\services\ModuleService $moduleService * @var \kernel\services\ModuleService $moduleService
*/ */
use kernel\Flash;
use kernel\widgets\IconBtn\IconBtnActivateWidget;
use kernel\widgets\IconBtn\IconBtnDeactivateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnUpdateWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
use kernel\widgets\ModuleTabsWidget;
$meta = []; $meta = [];
$meta['columns'] = [ $meta['columns'] = [
"name" => "Название", "name" => "Название",
@ -25,35 +33,32 @@ $info_to_table['data'] = $modules_info;
$table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->addAction(function ($row, $url) use ($moduleService) { $table->addAction(function ($row, $url) use ($moduleService) {
$slug = $row['slug']; $slug = $row['slug'];
if ($moduleService->isActive($slug)) { if ($moduleService->isActive($slug)) {
$label = "Деактивировать"; $url = "$url/deactivate/?slug=". $row['slug'];
$btn_type = "warning";
$btn = "<a class='btn btn-$btn_type' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
return IconBtnDeactivateWidget::create(['url' => $url])->run();
} else { } else {
$label = "<i class='fa-regular fa-circle-check'></i>"; $url = "$url/activate/?slug=". $row['slug'];
$btn_type = "success";
$btn = "<a class='btn btn-$btn_type' href='$url/activate/?slug=$slug' style='margin: 3px;' >$label</a>";
}
return $btn; return IconBtnActivateWidget::create(['url' => $url])->run();
}
}); });
$table->addAction(function ($row, $url) use ($moduleService) { $table->addAction(function ($row, $url) use ($moduleService) {
$slug = $row['slug']; $url = "$url/view/?slug=". $row['slug'];
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
return IconBtnViewWidget::create(['url' => $url])->run();
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; if ($moduleService->isShopModule($row['slug'])){
if (!$moduleService->isKernelModule($slug)){ if (!$moduleService->isLastVersion($row['slug'])) {
if (!$moduleService->isLastVersion($slug)) { $url = "$url/update/?slug=". $row['slug'];
$label = "Обновить";
$btn_type = "info"; return IconBtnUpdateWidget::create(['url' => $url])->run();
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
} }
} }
@ -62,16 +67,19 @@ $table->addAction(function ($row, $url) use ($moduleService){
$table->addAction(function ($row) use ($moduleService){ $table->addAction(function ($row) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
if (!$moduleService->isKernelModule($slug)){ if (!$moduleService->isKernelModule($slug)) {
$label = "Удалить"; $url = "admin/module_shop_client/delete/?slug=" . $row['slug'];
$btn_type = "danger";
return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; return IconBtnDeleteWidget::create(['url' => $url])->run();
} }
return false; return false;
}); });
$table->create();
if ($moduleService->isActive('module_shop_client')) { if ($moduleService->isActive('module_shop_client')) {
\kernel\widgets\ModuleTabsWidget::create()->run(); ModuleTabsWidget::create()->run();
} }
$table->create();
$table->render(); $table->render();

View File

@ -3,9 +3,8 @@
* @var array $data * @var array $data
*/ */
use kernel\IGTabel\btn\DangerBtn; use Itguild\Tables\ViewJsonTable;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\widgets\IconBtn\IconBtnListWidget;
use kernel\IGTabel\btn\SuccessBtn;
$table_info = [ $table_info = [
"meta" => [ "meta" => [
@ -20,11 +19,10 @@ $table_info = [
], ],
"data" => $data "data" => $data
]; ];
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $table = new ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->beforePrint(function () { $table->beforePrint(function () {
$btn = PrimaryBtn::create("Список", "/admin")->fetch(); return IconBtnListWidget::create(['url' => '/admin'])->run();
return $btn;
}); });
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -0,0 +1,10 @@
<?php
/**
* @var string $label
* @var string $btn_type
* @var string $url
* @var string $title
*/
?>
<a title="<?= $title ?>" class='btn btn-<?= $btn_type ?>' href='<?= $url ?>' style='margin: 3px' ><?= $label ?></a>

View File

@ -1,9 +0,0 @@
<?php
/**
* @var string $icon
* @var string $btn
* @var string $url
*/
?>
"<a class='btn btn-$btn' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$icon</a>";

View File

@ -18,7 +18,7 @@
</ul> </ul>
</li> </li>
<?php else: ?> <?php else: ?>
<li class="<?= $item->url === \kernel\Request::getUrlPath() || $item->url . "/module_shop_client" === \kernel\Request::getUrlPath() ? "active" : "" ?>"> <li class="<?= $item->url === \kernel\Request::getUrlPath() ? "active" : "" ?>">
<a href="<?= $item->url ?>"><?= $item->label ?></a> <a href="<?= $item->url ?>"><?= $item->label ?></a>
</li> </li>
<?php endif; ?> <?php endif; ?>

View File

@ -2,15 +2,24 @@
namespace kernel\widgets; namespace kernel\widgets;
use kernel\helpers\Debug;
use kernel\Widget; use kernel\Widget;
class ActionButtonWidget extends Widget class ActionButtonWidget extends Widget
{ {
public function run(): void
public static function create(array $data = []): ActionButtonWidget
{ {
$icon = $this->data['icon']; return new static($data);
$btn = $this->data['btn']; }
public function run(): string
{
$label = $this->data['label'];
$btn_type = $this->data['btn_type'];
$url = $this->data['url']; $url = $this->data['url'];
$this->cgView->render('/admin/action_button.php', ['icon' => $icon, 'btn' => $btn, 'url' => $url]); $title = $this->data['title'] ?? '';
return $this->cgView->fetch('/action_button.php', ['label' => $label, 'btn_type' => $btn_type, 'url' => $url, 'title' => $title]);
} }
} }

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnActivateWidget extends Widget
{
public static function create(array $data = []): IconBtnActivateWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-circle-check'></i>",
'url' => $url,
'btn_type' => "success",
'title' => "Активировать"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnCreateWidget extends Widget
{
public static function create(array $data = []): IconBtnCreateWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-square-plus'></i>",
'url' => $url,
'btn_type' => "success",
'title' => "Создать"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnDeactivateWidget extends Widget
{
public static function create(array $data = []): IconBtnDeactivateWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-circle-xmark'></i>",
'url' => $url,
'btn_type' => "warning",
'title' => "Деактивировать"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnDeleteWidget extends Widget
{
public static function create(array $data = []): IconBtnDeleteWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-trash-can'></i>",
'url' => $url,
'btn_type' => "danger",
'title' => "Удалить"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnEditWidget extends Widget
{
public static function create(array $data = []): IconBtnEditWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-solid fa-pen'></i>",
'url' => $url,
'btn_type' => "success",
'title' => "Редактировать"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnInstallWidget extends Widget
{
public static function create(array $data = []): IconBtnInstallWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-solid fa-download'></i>",
'url' => $url,
'btn_type' => "success",
'title' => "Установить"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnListWidget extends Widget
{
public static function create(array $data = []): IconBtnListWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-rectangle-list'></i>",
'url' => $url,
'btn_type' => "primary",
'title' => "Список"
])->run();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnUpdateWidget extends Widget
{
public static function create(array $data = []): IconBtnUpdateWidget
{
return new static($data);
}
public function run()
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'label' => "<i class='fa-solid fa-cloud-arrow-down'></i>",
'url' => $url,
'btn_type' => "info",
'title' => "Обновить"
])->run();
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnViewWidget extends Widget
{
public static function create(array $data = []): IconBtnViewWidget
{
return new static($data);
}
public function run(): string
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>",
'url' => $url,
'title' => "Просмотреть"
])->run();
}
}

View File

@ -11,7 +11,7 @@ class MenuWidget extends Widget
public function run(): void public function run(): void
{ {
$menu = Menu::where("parent_id", 0)->get()->sortBy("priority"); $menu = Menu::where("parent_id", 0)->get()->sortBy("priority");
$this->cgView->render('/admin/menu.php', ['menu' => $menu]); $this->cgView->render('/menu.php', ['menu' => $menu]);
} }
} }

View File

@ -13,6 +13,6 @@ class ModuleTabsWidget extends Widget
'/admin' => 'Локальные', '/admin' => 'Локальные',
'/admin/module_shop_client' => 'Каталог' '/admin/module_shop_client' => 'Каталог'
]; ];
$this->cgView->render('/admin/module_tabs.php', ['tabs' => $tabs]); $this->cgView->render('/tabs.php', ['tabs' => $tabs]);
} }
} }

View File

@ -0,0 +1,18 @@
<?php
namespace kernel\widgets;
use kernel\helpers\Debug;
use kernel\Widget;
class TagTabsWidget extends Widget
{
public function run(): void
{
$tabs = [
'/admin/tag' => 'tag',
'/admin/tag_entity' => 'tag entity'
];
$this->cgView->render('/tabs.php', ['tabs' => $tabs]);
}
}