From af25c49068fa7da7f585c4ed51559ce2b5d3cc34 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 6 Jul 2023 23:42:46 +0800 Subject: [PATCH 01/51] next --- composer.json | 3 ++- src/Enum/MenuTarget.php | 25 +++++-------------------- src/Enum/UserEnabled.php | 23 ++++------------------- src/Enum/UserVerified.php | 23 ++++------------------- 4 files changed, 15 insertions(+), 59 deletions(-) diff --git a/composer.json b/composer.json index e3278ef8..8bed988e 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ ] }, "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "2.x-dev", + "dev-next": "2.1.x-dev", } } } diff --git a/src/Enum/MenuTarget.php b/src/Enum/MenuTarget.php index 38d4adc7..20286d58 100644 --- a/src/Enum/MenuTarget.php +++ b/src/Enum/MenuTarget.php @@ -26,32 +26,17 @@ * @method static $this PARENT() * @method static $this TOP() */ -class MenuTarget extends EnumSingleton implements EnumTranslatableInterface +enum MenuTarget: string implements EnumTranslatableInterface { use EnumTranslatableTrait; - public const BLANK = '_blank'; + case BLANK = '_blank'; - public const SELF = '_self'; + case SELF = '_self'; - public const PARENT = '_parent'; + case PARENT = '_parent'; - public const TOP = '_top'; - - /** - * Creates a new value of some type - * - * @psalm-pure - * - * @param mixed $value - * - * @psalm-param T $value - * @throws UnexpectedValueException if incompatible type is given. - */ - public function __construct(mixed $value) - { - parent::__construct($value ?: static::SELF); - } + case TOP = '_top'; public function trans(LanguageInterface $lang, ...$args): string { diff --git a/src/Enum/UserEnabled.php b/src/Enum/UserEnabled.php index 086f30b2..f63affb0 100644 --- a/src/Enum/UserEnabled.php +++ b/src/Enum/UserEnabled.php @@ -24,28 +24,13 @@ * @method static $this ENABLED() * @method static $this DISABLED() */ -class UserEnabled extends EnumSingleton implements EnumTranslatableInterface +enum UserEnabled: int implements EnumTranslatableInterface { use EnumTranslatableTrait; - public const ENABLED = 1; - - public const DISABLED = 0; - - /** - * Creates a new value of some type - * - * @psalm-pure - * - * @param mixed $value - * - * @psalm-param T $value - * @throws UnexpectedValueException if incompatible type is given. - */ - public function __construct(mixed $value) - { - parent::__construct($value); - } + case ENABLED = 1; + + case DISABLED = 0; public function trans(LanguageInterface $lang, ...$args): string { diff --git a/src/Enum/UserVerified.php b/src/Enum/UserVerified.php index e1114460..209b75a7 100644 --- a/src/Enum/UserVerified.php +++ b/src/Enum/UserVerified.php @@ -24,28 +24,13 @@ * @method static $this VERIFIED() * @method static $this UNVERIFIED() */ -class UserVerified extends EnumSingleton implements EnumTranslatableInterface +enum UserVerified: int implements EnumTranslatableInterface { use EnumTranslatableTrait; - public const VERIFIED = 1; - - public const UNVERIFIED = 0; - - /** - * Creates a new value of some type - * - * @psalm-pure - * - * @param mixed $value - * - * @psalm-param T $value - * @throws UnexpectedValueException if incompatible type is given. - */ - public function __construct(mixed $value) - { - parent::__construct($value); - } + case VERIFIED = 1; + + case UNVERIFIED = 0; public function trans(LanguageInterface $lang, ...$args): string { From a1d1594258a8f8afc5189d00032066a1557409a1 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Fri, 7 Jul 2023 02:55:12 +0800 Subject: [PATCH 02/51] composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8bed988e..82858d1b 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ }, "branch-alias": { "dev-master": "2.x-dev", - "dev-next": "2.1.x-dev", + "dev-next": "2.1.x-dev" } } } From 79bf0ff2c856cf1b55e1e09b12ef09dc09dc938a Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Fri, 7 Jul 2023 03:16:57 +0800 Subject: [PATCH 03/51] default value --- src/Enum/MenuTarget.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Enum/MenuTarget.php b/src/Enum/MenuTarget.php index 20286d58..e3f156a9 100644 --- a/src/Enum/MenuTarget.php +++ b/src/Enum/MenuTarget.php @@ -38,6 +38,11 @@ enum MenuTarget: string implements EnumTranslatableInterface case TOP = '_top'; + public static function preprocessValue(mixed $value): mixed + { + return $value ?: self::SELF; + } + public function trans(LanguageInterface $lang, ...$args): string { return $lang->trans('luna.menu.field.target.option.' . $this->getKey()); From 0855237d4c629867a72b8358210dbfe152948000 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 9 Jul 2023 03:12:27 +0800 Subject: [PATCH 04/51] app enum --- etc/user.php | 2 +- src/Access/AccessService.php | 3 ++- src/LunaPackage.php | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/etc/user.php b/etc/user.php index 903e9461..a7178db4 100644 --- a/etc/user.php +++ b/etc/user.php @@ -23,7 +23,7 @@ 'user' => [ 'enabled' => true, - 'login_name' => 'username', + 'login_name' => 'email', 'remember_expires' => '+100days', diff --git a/src/Access/AccessService.php b/src/Access/AccessService.php index 824a9321..cdf351e7 100644 --- a/src/Access/AccessService.php +++ b/src/Access/AccessService.php @@ -21,6 +21,7 @@ use Lyrasoft\Luna\Tree\TreeBuilder; use Lyrasoft\Luna\User\UserEntityInterface; use Lyrasoft\Luna\User\UserService; +use Windwalker\Core\Application\AppClient; use Windwalker\Core\Application\ApplicationInterface; use Windwalker\ORM\NestedSetMapper; use Windwalker\ORM\ORM; @@ -749,7 +750,7 @@ protected static function extractAction(string $action): array */ protected function isAdminUserSwitched(): bool { - if ($this->app->getClient() === ApplicationInterface::CLIENT_WEB) { + if ($this->app->getClient() === AppClient::WEB) { $userSwitcher = $this->app->service(UserSwitchService::class); $luna = $this->app->service(LunaPackage::class); diff --git a/src/LunaPackage.php b/src/LunaPackage.php index 0bff6e40..522930e3 100644 --- a/src/LunaPackage.php +++ b/src/LunaPackage.php @@ -33,6 +33,7 @@ use Lyrasoft\Luna\User\UserService; use Lyrasoft\Luna\Widget\WidgetService; use Windwalker\Authorization\Authorization; +use Windwalker\Core\Application\AppClient; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Application\ApplicationInterface; use Windwalker\Core\Application\WebApplicationInterface; @@ -162,7 +163,7 @@ public function isFront(): bool public function bootBeforeRequest(Container $container): void { // Error - if (!$this->app->isDebug() && $this->app->getClient() === ApplicationInterface::CLIENT_WEB) { + if (!$this->app->isDebug() && $this->app->getClient() === AppClient::WEB) { $errorService = $container->get(ErrorService::class); $errorService->addHandler( From a71e0c8ac146708d0f8d738406a72eb2191ae603 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 10 Jul 2023 00:58:00 +0800 Subject: [PATCH 05/51] secret --- src/Module/Front/Auth/ForgetController.php | 5 +++-- src/PageBuilder/PageService.php | 2 +- src/User/ActivationService.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Module/Front/Auth/ForgetController.php b/src/Module/Front/Auth/ForgetController.php index f4184456..24a5147e 100644 --- a/src/Module/Front/Auth/ForgetController.php +++ b/src/Module/Front/Auth/ForgetController.php @@ -60,7 +60,8 @@ public function request( [ 'email' => $email, ], - $app->config('app.secret') + $app->getSecret(), + 'HS256' ); $link = $nav->to('forget_confirm', ['token' => $token, 'email' => idn_to_ascii($email)]) @@ -132,7 +133,7 @@ public function reset(AppContext $app, UserService $userService, ORM $orm, Navig $payload = JWT::decode( $token, - new Key($app->config('app.secret'), 'HS256'), + new Key($app->getSecret(), 'HS256'), ); $email = $payload->email ?? null; diff --git a/src/PageBuilder/PageService.php b/src/PageBuilder/PageService.php index b4286081..d9b9bcae 100644 --- a/src/PageBuilder/PageService.php +++ b/src/PageBuilder/PageService.php @@ -129,6 +129,6 @@ protected function secretHash(string $salt, string|int $id): string protected function getAppSecret(): string { - return $this->app->config('app.secret') ?? ''; + return $this->app->getSecret() ?? ''; } } diff --git a/src/User/ActivationService.php b/src/User/ActivationService.php index fff73f5d..5f198831 100644 --- a/src/User/ActivationService.php +++ b/src/User/ActivationService.php @@ -55,7 +55,7 @@ public function createToken(object $user): string { return JWT::encode( $this->getUserInfo($user), - $this->app->config('app.secret'), + $this->app->getSecret(), $this->tokenAlgo ); } @@ -64,7 +64,7 @@ public function decodeToken(string $token): array { return (array) JWT::decode( $token, - new Key($this->app->config('app.secret'), $this->tokenAlgo) + new Key($this->app->getSecret(), $this->tokenAlgo) ); } From e727ea2ddc8a7c85e91e0f66db9e15d6c98a718e Mon Sep 17 00:00:00 2001 From: chokeslam Date: Wed, 12 Jul 2023 12:19:15 +0800 Subject: [PATCH 06/51] add args --- src/Module/Front/Auth/ForgetController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Module/Front/Auth/ForgetController.php b/src/Module/Front/Auth/ForgetController.php index f4184456..7724c1dc 100644 --- a/src/Module/Front/Auth/ForgetController.php +++ b/src/Module/Front/Auth/ForgetController.php @@ -60,7 +60,8 @@ public function request( [ 'email' => $email, ], - $app->config('app.secret') + $app->config('app.secret'), + 'HS256' ); $link = $nav->to('forget_confirm', ['token' => $token, 'email' => idn_to_ascii($email)]) From f84e24c0e521133f958472d285de482790c8fd9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Jul 2023 08:09:08 +0000 Subject: [PATCH 07/51] Bump semver from 5.7.1 to 5.7.2 in /assets Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] --- assets/yarn.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/yarn.lock b/assets/yarn.lock index 570cd33f..920ff700 100644 --- a/assets/yarn.lock +++ b/assets/yarn.lock @@ -4721,19 +4721,19 @@ semver-greatest-satisfied-range@^1.1.0: sver-compat "^1.5.0" "semver@2 || 3 || 4 || 5": - version "5.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== + version "5.7.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" + integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" - integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + version "6.3.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" + integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== semver@^7.3.2, semver@^7.3.5, semver@^7.3.8: - version "7.5.3" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e" - integrity sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ== + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== dependencies: lru-cache "^6.0.0" From f06e5b4425bcbae043ad6bcea6b17d383d164955 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 17 Jul 2023 02:09:01 +0800 Subject: [PATCH 08/51] Fix enum --- views/menu/bootstrap5/link/link-nav.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/menu/bootstrap5/link/link-nav.blade.php b/views/menu/bootstrap5/link/link-nav.blade.php index 81ee5eb8..66f8359c 100644 --- a/views/menu/bootstrap5/link/link-nav.blade.php +++ b/views/menu/bootstrap5/link/link-nav.blade.php @@ -45,7 +45,7 @@ > getTarget() : false) + @attr('target', $link ? (string) $item->getTarget()->value : false) @attr('data-bs-target', $click ? "#$id" : false) @attr('data-bs-toggle', $click && $hasChildren ? 'collapse' : false)> {{ $item->getTitle() }} @@ -68,7 +68,7 @@ data-level="{{ $level }}"> getTarget() : false) + @attr('target', $link ? (string) $item->getTarget()->value : false) > @if ($item->getIcon()) From 6903fea14606df5c33f18a8b5e9b9b2c7093211c Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 22 Jul 2023 15:07:17 +0800 Subject: [PATCH 09/51] redirect --- src/Module/Front/Auth/AuthController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Module/Front/Auth/AuthController.php b/src/Module/Front/Auth/AuthController.php index 02d27cd4..24c75669 100644 --- a/src/Module/Front/Auth/AuthController.php +++ b/src/Module/Front/Auth/AuthController.php @@ -130,7 +130,12 @@ public function register( $app->getState()->remember('reg.data', $user); /** @var User $user */ - $user = $repository->register($user, RegistrationForm::class); + try { + $user = $repository->register($user, RegistrationForm::class); + } catch (\Throwable $e) { + $app->addMessage($e->getMessage(), 'warning'); + return $nav->to('registration'); + } $this->saveUserRoles($user, $userService->getAccessService()); From ea0477aaefeaea2331a70c67f85844287c7fb93e Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 22 Jul 2023 15:11:50 +0800 Subject: [PATCH 10/51] target --- views/menu/bootstrap5/link/link-dropdown.blade.php | 11 ++++++++--- views/menu/bootstrap5/link/link-nav.blade.php | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/views/menu/bootstrap5/link/link-dropdown.blade.php b/views/menu/bootstrap5/link/link-dropdown.blade.php index 591eed69..ca7bbdb3 100644 --- a/views/menu/bootstrap5/link/link-dropdown.blade.php +++ b/views/menu/bootstrap5/link/link-dropdown.blade.php @@ -16,6 +16,7 @@ * @var $lang LangService The language translation service. */ +use Lyrasoft\Luna\Menu\Tree\MenuNode; use Lyrasoft\Luna\Menu\View\LinkMenuView; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Asset\AssetService; @@ -24,6 +25,11 @@ use Windwalker\Core\Router\Navigator; use Windwalker\Core\Router\SystemUri; use Lyrasoft\Luna\Module\Admin\Menu\MenuListView; +use Windwalker\Utilities\TypeCast; + +/** + * @var $item MenuNode + */ $link = ($link === LinkMenuView::NO_LINK || (string) $link === '') ? false : $link; ?> @@ -33,7 +39,7 @@ data-menu-id="{{ $item->getValue()?->getId() }}" data-level="{{ $level }}"> getTarget() : false) + @attr('target', $link ? TypeCast::toString($item->getTarget()) : false) @attr('data-bs-toggle', $click && $hasChildren ? 'dropdown' : false)> {{ $item->getTitle() }} @@ -52,8 +58,7 @@ class="nav-link {{ $hasChildren ? 'dropdown-toggle' : '' }} {{ $item->isActive(t data-menu-id="{{ $item->getValue()?->getId() }}" data-level="{{ $level }}"> getTarget() : false) + @attr('target', $link ? TypeCast::toString($item->getTarget()) : false) > @if ($item->getIcon()) diff --git a/views/menu/bootstrap5/link/link-nav.blade.php b/views/menu/bootstrap5/link/link-nav.blade.php index 66f8359c..f0129342 100644 --- a/views/menu/bootstrap5/link/link-nav.blade.php +++ b/views/menu/bootstrap5/link/link-nav.blade.php @@ -26,6 +26,8 @@ use Windwalker\Core\Router\SystemUri; use Lyrasoft\Luna\Module\Admin\Menu\MenuListView; +use Windwalker\Utilities\TypeCast; + use function Windwalker\uid; $id = $id ?? 'menu-' . uid(); @@ -45,7 +47,7 @@ > getTarget()->value : false) + @attr('target', $link ? TypeCast::toString($item->getTarget()) : false) @attr('data-bs-target', $click ? "#$id" : false) @attr('data-bs-toggle', $click && $hasChildren ? 'collapse' : false)> {{ $item->getTitle() }} @@ -68,7 +70,7 @@ data-level="{{ $level }}"> getTarget()->value : false) + @attr('target', $link ? TypeCast::toString($item->getTarget()) : false) > @if ($item->getIcon()) From 4d82e0a3d3f60d8b66597cae14558229c6d571a6 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Wed, 26 Jul 2023 18:03:58 +0800 Subject: [PATCH 11/51] Use Password Hasher --- src/Auth/LunaAuthMethod.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Auth/LunaAuthMethod.php b/src/Auth/LunaAuthMethod.php index f9bddf89..3408556c 100644 --- a/src/Auth/LunaAuthMethod.php +++ b/src/Auth/LunaAuthMethod.php @@ -13,12 +13,12 @@ use JsonException; use Lyrasoft\Luna\Entity\User; -use Lyrasoft\Luna\User\PasswordInterface; use ReflectionException; use Symfony\Component\OptionsResolver\OptionsResolver; use Windwalker\Authentication\AuthResult; use Windwalker\Authentication\Method\MethodInterface; use Windwalker\Core\Runtime\Config; +use Windwalker\Crypt\Hasher\PasswordHasherInterface; use Windwalker\Data\Collection; use Windwalker\ORM\EntityMapper; use Windwalker\ORM\ORM; @@ -36,15 +36,15 @@ class LunaAuthMethod implements MethodInterface /** * DatabaseMethod constructor. * - * @param ORM $orm - * @param Config $config - * @param PasswordInterface $password - * @param array $options + * @param ORM $orm + * @param Config $config + * @param PasswordHasherInterface $password + * @param array $options */ public function __construct( protected ORM $orm, protected Config $config, - protected PasswordInterface $password, + protected PasswordHasherInterface $password, array $options = [] ) { $this->resolveOptions( From af9b46f19bd8cf279315d1e70a429a085d6b15ad Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Wed, 26 Jul 2023 18:04:11 +0800 Subject: [PATCH 12/51] Use Password Hasher --- src/User/Password.php | 103 ++------------------------------- src/User/PasswordInterface.php | 12 ++-- 2 files changed, 12 insertions(+), 103 deletions(-) diff --git a/src/User/Password.php b/src/User/Password.php index c27bb4a7..0840e3bb 100644 --- a/src/User/Password.php +++ b/src/User/Password.php @@ -11,105 +11,14 @@ namespace Lyrasoft\Luna\User; +use Windwalker\Crypt\Hasher\PasswordHasher; + /** * The Password class. + * + * @deprecated Use PasswordHasher */ -class Password implements PasswordInterface +class Password extends PasswordHasher implements PasswordInterface { - public function __construct(protected string $algo = PASSWORD_DEFAULT, protected array $options = []) - { - } - - public function hash(string $password): string - { - return password_hash($password, $this->getAlgo(), $this->getOptions()); - } - - public function verify(string $password, string $hash): bool - { - return password_verify($password, $hash); - } - - public function needsRehash(string $password): bool - { - return password_needs_rehash($password, $this->getAlgo(), $this->getOptions()); - } - - /** - * @return string - */ - public function getAlgo(): string - { - return $this->algo; - } - - /** - * @param string $algo - * - * @return static Return self to support chaining. - */ - public function setAlgo(string $algo): static - { - $this->algo = $algo; - - return $this; - } - - /** - * @return array - */ - public function getOptions(): array - { - return $this->options; - } - - /** - * @param array $options - * - * @return static Return self to support chaining. - */ - public function setOptions(array $options): static - { - $this->options = $options; - - return $this; - } - - /** - * Generate a random password. - * - * This is a fork of Joomla JUserHelper::genRandomPassword() - * - * @param integer $length Length of the password to generate - * - * @return string Random Password - * - * @throws \Exception - * @see https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/user/helper.php#L642 - */ - public static function genRandomPassword( - int $length = 16, - $seed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' - ): string { - $base = strlen($seed); - $password = ''; - - /* - * Start with a cryptographic strength random string, then convert it to - * a string with the numeric base of the salt. - * Shift the base conversion on each character so the character - * distribution is even, and randomize the start shift so it's not - * predictable. - */ - $random = random_bytes($length + 1); - $shift = ord($random[0]); - - for ($i = 1; $i <= $length; ++$i) { - $password .= $seed[($shift + ord($random[$i])) % $base]; - - $shift += ord($random[$i]); - } - - return $password; - } + // } diff --git a/src/User/PasswordInterface.php b/src/User/PasswordInterface.php index 271c25b1..a75d881a 100644 --- a/src/User/PasswordInterface.php +++ b/src/User/PasswordInterface.php @@ -11,14 +11,14 @@ namespace Lyrasoft\Luna\User; +use Windwalker\Crypt\Hasher\PasswordHasherInterface; + /** * Interface PasswordInterface + * + * @deprecated Use PasswordHasherInterface */ -interface PasswordInterface +interface PasswordInterface extends PasswordHasherInterface { - public function hash(string $password): string; - - public function verify(string $password, string $hash): bool; - - public function needsRehash(string $password): bool; + // } From 45948e9c0393f65616e726294b1bd1ab7bf78777 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Wed, 26 Jul 2023 18:04:18 +0800 Subject: [PATCH 13/51] table-responsive-lg --- src/Module/Admin/Language/views/language-list.blade.php | 2 +- src/Module/Admin/Menu/views/menu-list.blade.php | 2 +- src/Module/Admin/Page/views/page-list.blade.php | 2 +- src/Module/Admin/Tag/views/tag-list.blade.php | 2 +- src/Module/Admin/Widget/views/widget-list.blade.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Module/Admin/Language/views/language-list.blade.php b/src/Module/Admin/Language/views/language-list.blade.php index e5b8068b..19adc869 100644 --- a/src/Module/Admin/Language/views/language-list.blade.php +++ b/src/Module/Admin/Language/views/language-list.blade.php @@ -56,7 +56,7 @@ @lang('unicorn.grid.responsive.table.desc') -
+
diff --git a/src/Module/Admin/Menu/views/menu-list.blade.php b/src/Module/Admin/Menu/views/menu-list.blade.php index 4276103f..faa0032f 100644 --- a/src/Module/Admin/Menu/views/menu-list.blade.php +++ b/src/Module/Admin/Menu/views/menu-list.blade.php @@ -64,7 +64,7 @@ @lang('unicorn.grid.responsive.table.desc')

-
+
diff --git a/src/Module/Admin/Page/views/page-list.blade.php b/src/Module/Admin/Page/views/page-list.blade.php index 46e9c633..e555d64a 100644 --- a/src/Module/Admin/Page/views/page-list.blade.php +++ b/src/Module/Admin/Page/views/page-list.blade.php @@ -53,7 +53,7 @@ @lang('unicorn.grid.responsive.table.desc')

-
+
diff --git a/src/Module/Admin/Tag/views/tag-list.blade.php b/src/Module/Admin/Tag/views/tag-list.blade.php index 2e225ec7..4697076e 100644 --- a/src/Module/Admin/Tag/views/tag-list.blade.php +++ b/src/Module/Admin/Tag/views/tag-list.blade.php @@ -51,7 +51,7 @@ @lang('unicorn.grid.responsive.table.desc')

-
+
diff --git a/src/Module/Admin/Widget/views/widget-list.blade.php b/src/Module/Admin/Widget/views/widget-list.blade.php index 085910a3..08bdb5bd 100644 --- a/src/Module/Admin/Widget/views/widget-list.blade.php +++ b/src/Module/Admin/Widget/views/widget-list.blade.php @@ -58,7 +58,7 @@ @lang('unicorn.grid.responsive.table.desc') -
+
From 15cd665330e13f510c7fcbf18e8e7b13198028af Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 29 Jul 2023 21:20:51 +0800 Subject: [PATCH 14/51] prepare password hasher --- src/LunaPackage.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/LunaPackage.php b/src/LunaPackage.php index 522930e3..f2fe07c3 100644 --- a/src/LunaPackage.php +++ b/src/LunaPackage.php @@ -44,6 +44,8 @@ use Windwalker\Core\Package\PackageInstaller; use Windwalker\Core\Seed\FakerService; use Windwalker\Core\Service\ErrorService; +use Windwalker\Crypt\Hasher\PasswordHasher; +use Windwalker\Crypt\Hasher\PasswordHasherInterface; use Windwalker\DI\Attributes\AttributeType; use Windwalker\DI\Container; use Windwalker\DI\ServiceProviderInterface; @@ -225,6 +227,15 @@ protected function registerAuthServices(Container $container): void ) ); } + + if (!$container->has(PasswordHasherInterface::class)) { + $container->share( + PasswordHasherInterface::class, + function (Container $container) { + return $container->newInstance(PasswordHasher::class); + } + ); + } } public function install(PackageInstaller $installer): void From be97b7735db8b567ddb746953a3cef7c9d00d3d5 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 7 Sep 2023 18:34:36 +0800 Subject: [PATCH 15/51] app context --- src/LunaPackage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/LunaPackage.php b/src/LunaPackage.php index f2fe07c3..8fb5e2b0 100644 --- a/src/LunaPackage.php +++ b/src/LunaPackage.php @@ -36,6 +36,7 @@ use Windwalker\Core\Application\AppClient; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Application\ApplicationInterface; +use Windwalker\Core\Application\Context\AppContextInterface; use Windwalker\Core\Application\WebApplicationInterface; use Windwalker\Core\Auth\AuthService; use Windwalker\Core\DI\RequestBootableProviderInterface; @@ -202,7 +203,7 @@ protected function registerAuthServices(Container $container): void $container->prepareSharedObject( UserService::class, fn(UserService $userService, Container $container) - => $userService->addEventDealer($container->get(AppContext::class)) + => $userService->addEventDealer($container->get(AppContextInterface::class)) ); $container->prepareSharedObject(UserSwitchService::class); $container->prepareSharedObject(AccessService::class); From 4729245f9e37a77ed3ebcff53f245f2c555fddfb Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 25 Sep 2023 03:47:27 +0800 Subject: [PATCH 16/51] Fix for WS --- src/User/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/User/UserService.php b/src/User/UserService.php index 232bc9a5..f566be38 100644 --- a/src/User/UserService.php +++ b/src/User/UserService.php @@ -72,7 +72,7 @@ public function __construct( */ public function getCurrentUser(): UserEntityInterface { - return $this->getUser(); + return $this->currentUser; } /** @@ -86,7 +86,7 @@ public function getCurrentUser(): UserEntityInterface */ public function getUser(mixed $conditions = null): UserEntityInterface { - return $this->load($conditions) ?? $this->createUserEntity(); + return $this->getCurrentUser() ?? $this->load($conditions) ?? $this->createUserEntity(); } /** From 42c42944082e24fc7833b43dbf57fa739f34f43c Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 25 Sep 2023 17:34:42 +0800 Subject: [PATCH 17/51] Fix user service current user --- src/User/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/User/UserService.php b/src/User/UserService.php index f566be38..3efb0b10 100644 --- a/src/User/UserService.php +++ b/src/User/UserService.php @@ -72,7 +72,7 @@ public function __construct( */ public function getCurrentUser(): UserEntityInterface { - return $this->currentUser; + return $this->getUser(); } /** @@ -86,7 +86,7 @@ public function getCurrentUser(): UserEntityInterface */ public function getUser(mixed $conditions = null): UserEntityInterface { - return $this->getCurrentUser() ?? $this->load($conditions) ?? $this->createUserEntity(); + return $this->currentUser ?? $this->load($conditions) ?? $this->createUserEntity(); } /** From ee5f33fe0af48d450ef3716de8de37fe59e02d7a Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 1 Oct 2023 23:26:02 +0800 Subject: [PATCH 18/51] Fix Author & Modifier to not hard dep to UserService --- src/Attributes/Author.php | 4 ++-- src/Attributes/Modifier.php | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Attributes/Author.php b/src/Attributes/Author.php index a671c455..096773fa 100644 --- a/src/Attributes/Author.php +++ b/src/Attributes/Author.php @@ -24,8 +24,8 @@ class Author extends CastForSave { protected function getDefaultCaster(): callable { - return function (mixed $value, ORM $orm, object $entity, UserService $userService) { - if (!$value) { + return function (mixed $value, ORM $orm, object $entity, UserService $userService = null) { + if (!$value && $userService) { $mapper = $orm->mapper($entity::class); if ($mapper->canCheckIsNew()) { diff --git a/src/Attributes/Modifier.php b/src/Attributes/Modifier.php index dcd0a273..49dc7c11 100644 --- a/src/Attributes/Modifier.php +++ b/src/Attributes/Modifier.php @@ -24,7 +24,11 @@ class Modifier extends CastForSave { protected function getDefaultCaster(): callable { - return function (mixed $value, ORM $orm, object $entity, UserService $userService) { + return function (mixed $value, ORM $orm, object $entity, UserService $userService = null) { + if (!$userService) { + return $value; + } + $mapper = $orm->mapper($entity::class); if ($mapper->canCheckIsNew()) { From 316cad5c932d6dc4ae24dc8264971d00ca994ceb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 14:17:26 +0000 Subject: [PATCH 19/51] Bump postcss from 8.4.24 to 8.4.31 in /assets Bumps [postcss](https://github.com/postcss/postcss) from 8.4.24 to 8.4.31. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.24...8.4.31) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- assets/package.json | 2 +- assets/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/package.json b/assets/package.json index 492731a0..093409b2 100644 --- a/assets/package.json +++ b/assets/package.json @@ -16,7 +16,7 @@ "css-loader": "^6.7.0", "file-loader": "^6.2.0", "lodash-es": "^4.17.21", - "postcss": "^8.0", + "postcss": "^8.4", "postcss-loader": "^6.2.1", "sass-loader": "^12.6.0", "spectrum-vanilla": "^1.0.5", diff --git a/assets/yarn.lock b/assets/yarn.lock index 570cd33f..b0e1a414 100644 --- a/assets/yarn.lock +++ b/assets/yarn.lock @@ -4360,10 +4360,10 @@ postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.32: picocolors "^0.2.1" source-map "^0.6.1" -postcss@^8.0, postcss@^8.1.10, postcss@^8.4.21: - version "8.4.24" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.24.tgz#f714dba9b2284be3cc07dbd2fc57ee4dc972d2df" - integrity sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg== +postcss@^8.0, postcss@^8.1.10, postcss@^8.4, postcss@^8.4.21: + version "8.4.31" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d" + integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ== dependencies: nanoid "^3.3.6" picocolors "^1.0.0" From 7bd6f7642b3c59b45ebfb09d97dfd6061fb7c779 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 28 Oct 2023 15:46:33 +0800 Subject: [PATCH 20/51] create root if not exists --- resources/migrations/2021110708020001_UserInit.php | 4 ++-- resources/migrations/2021110708040001_CategoryInit.php | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/resources/migrations/2021110708020001_UserInit.php b/resources/migrations/2021110708020001_UserInit.php index 325067f5..73b04251 100644 --- a/resources/migrations/2021110708020001_UserInit.php +++ b/resources/migrations/2021110708020001_UserInit.php @@ -126,11 +126,11 @@ function (Schema $schema) { /** @var NestedSetMapper $roleMapper */ $roleMapper = $orm->mapper(UserRole::class); - $root = $roleMapper->createRoot(); + $root = $roleMapper->createRootIfNotExist(); $role = new UserRole(); $role->setTitle('Super User'); - $role->setState(BasicState::PUBLISHED()); + $role->setState(BasicState::PUBLISHED); $roleMapper->setPosition($role, $root->getPrimaryKeyValue()); $roleMapper->createOne($role); diff --git a/resources/migrations/2021110708040001_CategoryInit.php b/resources/migrations/2021110708040001_CategoryInit.php index 6914b3c3..1f4471c9 100644 --- a/resources/migrations/2021110708040001_CategoryInit.php +++ b/resources/migrations/2021110708040001_CategoryInit.php @@ -60,9 +60,7 @@ function (Schema $schema) { /** @var NestedSetMapper $mapper */ $mapper = $orm->mapper(Category::class); - if (!$mapper->getRoot()) { - $mapper->createRoot(); - } + $mapper->createRootIfNotExist(); } ); From c57ead2570a3790ffe2464b78b1a2fa0b44caba8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 28 Oct 2023 07:47:54 +0000 Subject: [PATCH 21/51] Bump @babel/traverse from 7.22.5 to 7.23.2 in /assets Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.22.5 to 7.23.2. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse) --- updated-dependencies: - dependency-name: "@babel/traverse" dependency-type: indirect ... Signed-off-by: dependabot[bot] --- assets/yarn.lock | 99 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/assets/yarn.lock b/assets/yarn.lock index e3dd3b8a..4b68703d 100644 --- a/assets/yarn.lock +++ b/assets/yarn.lock @@ -17,6 +17,14 @@ dependencies: "@babel/highlight" "^7.22.5" +"@babel/code-frame@^7.22.13": + version "7.22.13" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.13.tgz#e3c1c099402598483b7a8c46a721d1038803755e" + integrity sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w== + dependencies: + "@babel/highlight" "^7.22.13" + chalk "^2.4.2" + "@babel/compat-data@^7.17.7", "@babel/compat-data@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.22.5.tgz#b1f6c86a02d85d2dd3368a2b67c09add8cd0c255" @@ -53,6 +61,16 @@ "@jridgewell/trace-mapping" "^0.3.17" jsesc "^2.5.1" +"@babel/generator@^7.23.0": + version "7.23.0" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.0.tgz#df5c386e2218be505b34837acbcb874d7a983420" + integrity sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g== + dependencies: + "@babel/types" "^7.23.0" + "@jridgewell/gen-mapping" "^0.3.2" + "@jridgewell/trace-mapping" "^0.3.17" + jsesc "^2.5.1" + "@babel/helper-annotate-as-pure@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz#e7f06737b197d580a01edf75d97e2c8be99d3882" @@ -114,6 +132,11 @@ resolve "^1.14.2" semver "^6.1.2" +"@babel/helper-environment-visitor@^7.22.20": + version "7.22.20" + resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz#96159db61d34a29dba454c959f5ae4a649ba9167" + integrity sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA== + "@babel/helper-environment-visitor@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz#f06dd41b7c1f44e1f8da6c4055b41ab3a09a7e98" @@ -127,6 +150,14 @@ "@babel/template" "^7.22.5" "@babel/types" "^7.22.5" +"@babel/helper-function-name@^7.23.0": + version "7.23.0" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz#1f9a3cdbd5b2698a670c30d2735f9af95ed52759" + integrity sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw== + dependencies: + "@babel/template" "^7.22.15" + "@babel/types" "^7.23.0" + "@babel/helper-hoist-variables@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz#c01a007dac05c085914e8fb652b339db50d823bb" @@ -217,11 +248,23 @@ dependencies: "@babel/types" "^7.22.5" +"@babel/helper-split-export-declaration@^7.22.6": + version "7.22.6" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c" + integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g== + dependencies: + "@babel/types" "^7.22.5" + "@babel/helper-string-parser@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f" integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw== +"@babel/helper-validator-identifier@^7.22.20": + version "7.22.20" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0" + integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A== + "@babel/helper-validator-identifier@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" @@ -251,6 +294,15 @@ "@babel/traverse" "^7.22.5" "@babel/types" "^7.22.5" +"@babel/highlight@^7.22.13": + version "7.22.20" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.22.20.tgz#4ca92b71d80554b01427815e06f2df965b9c1f54" + integrity sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg== + dependencies: + "@babel/helper-validator-identifier" "^7.22.20" + chalk "^2.4.2" + js-tokens "^4.0.0" + "@babel/highlight@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.22.5.tgz#aa6c05c5407a67ebce408162b7ede789b4d22031" @@ -265,6 +317,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.5.tgz#721fd042f3ce1896238cf1b341c77eb7dee7dbea" integrity sha512-DFZMC9LJUG9PLOclRC32G63UXwzqS2koQC8dkx+PLdmt1xSePYpbT/NbsrJy8Q/muXz7o/h/d4A7Fuyixm559Q== +"@babel/parser@^7.22.15", "@babel/parser@^7.23.0": + version "7.23.0" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.0.tgz#da950e622420bf96ca0d0f2909cdddac3acd8719" + integrity sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw== + "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.22.5.tgz#87245a21cd69a73b0b81bcda98d443d6df08f05e" @@ -953,6 +1010,15 @@ dependencies: regenerator-runtime "^0.13.11" +"@babel/template@^7.22.15": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" + integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w== + dependencies: + "@babel/code-frame" "^7.22.13" + "@babel/parser" "^7.22.15" + "@babel/types" "^7.22.15" + "@babel/template@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.5.tgz#0c8c4d944509875849bd0344ff0050756eefc6ec" @@ -963,21 +1029,30 @@ "@babel/types" "^7.22.5" "@babel/traverse@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.5.tgz#44bd276690db6f4940fdb84e1cb4abd2f729ccd1" - integrity sha512-7DuIjPgERaNo6r+PZwItpjCZEa5vyw4eJGufeLxrPdBXBoLcCJCIasvK6pK/9DVNrLZTLFhUGqaC6X/PA007TQ== - dependencies: - "@babel/code-frame" "^7.22.5" - "@babel/generator" "^7.22.5" - "@babel/helper-environment-visitor" "^7.22.5" - "@babel/helper-function-name" "^7.22.5" + version "7.23.2" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.2.tgz#329c7a06735e144a506bdb2cad0268b7f46f4ad8" + integrity sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw== + dependencies: + "@babel/code-frame" "^7.22.13" + "@babel/generator" "^7.23.0" + "@babel/helper-environment-visitor" "^7.22.20" + "@babel/helper-function-name" "^7.23.0" "@babel/helper-hoist-variables" "^7.22.5" - "@babel/helper-split-export-declaration" "^7.22.5" - "@babel/parser" "^7.22.5" - "@babel/types" "^7.22.5" + "@babel/helper-split-export-declaration" "^7.22.6" + "@babel/parser" "^7.23.0" + "@babel/types" "^7.23.0" debug "^4.1.0" globals "^11.1.0" +"@babel/types@^7.22.15", "@babel/types@^7.23.0": + version "7.23.0" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.0.tgz#8c1f020c9df0e737e4e247c0619f58c68458aaeb" + integrity sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg== + dependencies: + "@babel/helper-string-parser" "^7.22.5" + "@babel/helper-validator-identifier" "^7.22.20" + to-fast-properties "^2.0.0" + "@babel/types@^7.22.5", "@babel/types@^7.4.4": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.5.tgz#cd93eeaab025880a3a47ec881f4b096a5b786fbe" @@ -1911,7 +1986,7 @@ caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001503: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001507.tgz#fae53f6286e7564783eadea9b447819410a59534" integrity sha512-SFpUDoSLCaE5XYL2jfqe9ova/pbQHEmbheDf5r4diNwbAgR3qxM9NQtfsiSscjqoya5K7kFcHPUQ+VsUkIJR4A== -chalk@^2.0.0, chalk@^2.4.1: +chalk@^2.0.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== From 1f5b2950c5ee359a449e760299281e5a25bca8a4 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 5 Nov 2023 02:30:21 +0800 Subject: [PATCH 22/51] renderer paths --- src/LunaPackage.php | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/LunaPackage.php b/src/LunaPackage.php index 8fb5e2b0..735f2a2e 100644 --- a/src/LunaPackage.php +++ b/src/LunaPackage.php @@ -43,6 +43,7 @@ use Windwalker\Core\Http\AppRequest; use Windwalker\Core\Package\AbstractPackage; use Windwalker\Core\Package\PackageInstaller; +use Windwalker\Core\Renderer\RendererService; use Windwalker\Core\Seed\FakerService; use Windwalker\Core\Service\ErrorService; use Windwalker\Crypt\Hasher\PasswordHasher; @@ -51,6 +52,7 @@ use Windwalker\DI\Container; use Windwalker\DI\ServiceProviderInterface; use Windwalker\Event\Event; +use Windwalker\Utilities\Iterator\PriorityQueue; use Windwalker\Utilities\StrNormalize; /** @@ -89,29 +91,19 @@ public function register(Container $container): void ->registerAttribute(LangAssoc::class, AttributeType::CALLABLE); // View - $container->mergeParameters( - 'renderer.paths', - [ - static::path('views'), - ], - Container::MERGE_OVERRIDE - ); - - $container->mergeParameters( - 'renderer.namespaces.@menu', - [ + $container->extend(RendererService::class, function (RendererService $rendererService) { + $rendererService->addPath(static::path('views'), PriorityQueue::BELOW_NORMAL); + $rendererService->addPath( static::path('views/menu/bootstrap5'), - ], - Container::MERGE_OVERRIDE - ); - - $container->mergeParameters( - 'renderer.namespaces.@theme', - [ + PriorityQueue::BELOW_NORMAL, + '@menu' + ); + $rendererService->addPath( static::path('views/ui/bootstrap5'), - ], - Container::MERGE_OVERRIDE - ); + PriorityQueue::BELOW_NORMAL, + '@theme' + ); + }); $container->mergeParameters( 'renderer.aliases', From 627aecaca20f8e5f81a54b5239206f83a54e42ef Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 6 Nov 2023 02:38:47 +0800 Subject: [PATCH 23/51] Rewrite all header docblocks --- bin/Console.php | 6 ------ bin/release.php | 6 ------ etc/access.php | 7 ------- etc/captcha.php | 7 ------- etc/luna.php | 7 ------- etc/menu.php | 7 ------- etc/pages.php | 7 ------- etc/social_login.php | 7 ------- etc/user.php | 7 ------- etc/widget.php | 7 ------- resources/migrations/2021110708010001_ConfigInit.php | 7 ------- resources/migrations/2021110708020001_UserInit.php | 7 ------- resources/migrations/2021110708030001_RuleInit.php | 7 ------- resources/migrations/2021110708040001_CategoryInit.php | 7 ------- resources/migrations/2021110708050001_ArticleInit.php | 7 ------- resources/migrations/2021110708110001_MenuInit.php | 7 ------- resources/migrations/2021111715240001_PageInit.php | 7 ------- resources/migrations/2021112206280001_TagInit.php | 7 ------- resources/migrations/2022011603100001_LanguageInit.php | 7 ------- resources/migrations/2022011618130001_AssociationInit.php | 7 ------- resources/migrations/2022020214590001_WidgetInit.php | 7 ------- resources/seeders/article-seeder.php | 7 ------- resources/seeders/category-seeder.php | 7 ------- resources/seeders/config-seeder.php | 7 ------- resources/seeders/language-seeder.php | 7 ------- resources/seeders/menu-seeder.php | 7 ------- resources/seeders/page-seeder.php | 7 ------- resources/seeders/tag-seeder.php | 7 ------- resources/seeders/user-seeder.php | 7 ------- resources/seeders/widget-seeder.php | 7 ------- routes/admin/config.route.php | 7 ------- routes/admin/luna.route.php | 7 ------- routes/front/article.route.php | 7 ------- routes/front/auth.route.php | 7 ------- routes/front/luna.route.php | 7 ------- routes/front/my.route.php | 7 ------- src/Access/AccessAuthorization.php | 7 ------- src/Access/AccessService.php | 7 ------- src/Attributes/Author.php | 7 ------- src/Attributes/LangAssoc.php | 7 ------- src/Attributes/Modifier.php | 7 ------- src/Attributes/PageSlugify.php | 7 ------- src/Attributes/Slugify.php | 7 ------- src/Auth/HASessionStorage.php | 7 ------- src/Auth/LunaAuthMethod.php | 7 ------- src/Auth/Profile/DefaultProfileHandler.php | 7 ------- src/Auth/Profile/FacebookProfileHandler.php | 7 ------- src/Auth/Profile/GoogleProfileHandler.php | 7 ------- src/Auth/Profile/ProfileHandlerInterface.php | 7 ------- src/Auth/Provider/LineSocialProvider.php | 7 ------- src/Auth/SocialAuthService.php | 7 ------- src/Captcha/CaptchaDriverInterface.php | 7 ------- src/Captcha/CaptchaImageInterface.php | 7 ------- src/Captcha/CaptchaManager.php | 7 ------- src/Captcha/GregwarDriver.php | 7 ------- src/Captcha/NullCaptchaDriver.php | 7 ------- src/Captcha/Recaptcha/WindwalkerRequestMethod.php | 7 ------- src/Captcha/RecaptchaDriver.php | 7 ------- src/Data/MetaData.php | 7 ------- src/Entity/Article.php | 7 ------- src/Entity/Association.php | 7 ------- src/Entity/Category.php | 7 ------- src/Entity/Config.php | 7 ------- src/Entity/Language.php | 7 ------- src/Entity/Menu.php | 7 ------- src/Entity/Page.php | 7 ------- src/Entity/PageTemplate.php | 7 ------- src/Entity/Rule.php | 7 ------- src/Entity/Session.php | 7 ------- src/Entity/Tag.php | 7 ------- src/Entity/TagMap.php | 7 ------- src/Entity/User.php | 7 ------- src/Entity/UserRole.php | 7 ------- src/Entity/UserRoleMap.php | 7 ------- src/Entity/UserSocial.php | 7 ------- src/Entity/Widget.php | 7 ------- src/Enum/MenuTarget.php | 7 ------- src/Enum/UserEnabled.php | 7 ------- src/Enum/UserVerified.php | 7 ------- src/Error/LunaErrorHandler.php | 7 ------- src/Faker/FakerHelper.php | 7 ------- src/Faker/LunaFakerProvider.php | 7 ------- src/Faker/zh_TW/Internet.php | 7 ------- src/Field/ArticleModalField.php | 7 ------- src/Field/CaptchaField.php | 7 ------- src/Field/CategoryListField.php | 7 ------- src/Field/CategoryModalField.php | 7 ------- src/Field/FlagListField.php | 7 ------- src/Field/LanguageListField.php | 7 ------- src/Field/LocaleSwitchField.php | 7 ------- src/Field/MenuListField.php | 7 ------- src/Field/MenuModalField.php | 7 ------- src/Field/MenuTypeListField.php | 7 ------- src/Field/MenuViewListField.php | 7 ------- src/Field/PageModalField.php | 7 ------- src/Field/TagListField.php | 7 ------- src/Field/UserModalField.php | 7 ------- src/Field/WidgetPositionListField.php | 7 ------- src/Helper/PravatarHelper.php | 7 ------- src/Helper/TempFile.php | 7 ------- src/Helper/UnsplashHelper.php | 7 ------- src/Locale/LanguageAssocTrait.php | 7 ------- src/Locale/LocaleAwareTrait.php | 7 ------- src/LunaPackage.php | 7 ------- src/Menu/AbstractMenuView.php | 7 ------- src/Menu/LayoutRenderedMenuInterface.php | 7 ------- src/Menu/MenuBuilder.php | 7 ------- src/Menu/MenuFieldDefineEvent.php | 7 ------- src/Menu/SelfRenderMenuInterface.php | 7 ------- src/Menu/SelfRenderMenuTrait.php | 7 ------- src/Menu/Tree/DbMenuNode.php | 7 ------- src/Menu/Tree/MenuNode.php | 7 ------- src/Menu/Tree/MenuNodeInterface.php | 7 ------- src/Menu/View/AliasMenuView.php | 7 ------- src/Menu/View/ArticleCategoryMenuView.php | 7 ------- src/Menu/View/ArticleMenuView.php | 7 ------- src/Menu/View/LinkMenuView.php | 7 ------- src/Menu/View/PageMenuView.php | 7 ------- src/Menu/View/PlaceholderMenuView.php | 7 ------- src/Menu/View/RouteMenuView.php | 7 ------- src/Middleware/AccessMiddleware.php | 7 ------- src/Middleware/AdminAccessMiddleware.php | 7 ------- src/Middleware/LangAssocMiddleware.php | 7 ------- src/Middleware/LocaleMiddleware.php | 7 ------- src/Middleware/LoginRequireMiddleware.php | 7 ------- src/Module/Admin/Article/ArticleController.php | 7 ------- src/Module/Admin/Article/ArticleEditView.php | 7 ------- src/Module/Admin/Article/ArticleListView.php | 7 ------- src/Module/Admin/Article/Form/EditForm.php | 7 ------- src/Module/Admin/Article/Form/GridForm.php | 7 ------- src/Module/Admin/Auth/AuthController.php | 7 ------- src/Module/Admin/Auth/AuthLoginView.php | 7 ------- src/Module/Admin/Auth/Form/LoginForm.php | 7 ------- src/Module/Admin/Auth/auth.config.php | 7 ------- src/Module/Admin/Category/CategoryController.php | 7 ------- src/Module/Admin/Category/CategoryEditView.php | 7 ------- src/Module/Admin/Category/CategoryListView.php | 7 ------- src/Module/Admin/Category/Form/EditForm.php | 7 ------- src/Module/Admin/Category/Form/GridForm.php | 7 ------- src/Module/Admin/Config/ConfigController.php | 7 ------- src/Module/Admin/Config/ConfigEditView.php | 7 ------- src/Module/Admin/Config/Form/CoreForm.php | 7 ------- src/Module/Admin/Language/Form/EditForm.php | 7 ------- src/Module/Admin/Language/Form/GridForm.php | 7 ------- src/Module/Admin/Language/LanguageAjaxController.php | 7 ------- src/Module/Admin/Language/LanguageController.php | 7 ------- src/Module/Admin/Language/LanguageEditView.php | 7 ------- src/Module/Admin/Language/LanguageListView.php | 7 ------- src/Module/Admin/Menu/Form/EditForm.php | 7 ------- src/Module/Admin/Menu/Form/GridForm.php | 7 ------- src/Module/Admin/Menu/MenuController.php | 7 ------- src/Module/Admin/Menu/MenuEditView.php | 7 ------- src/Module/Admin/Menu/MenuListView.php | 7 ------- src/Module/Admin/Page/Form/EditForm.php | 7 ------- src/Module/Admin/Page/Form/GridForm.php | 7 ------- src/Module/Admin/Page/PageController.php | 7 ------- src/Module/Admin/Page/PageEditView.php | 7 ------- src/Module/Admin/Page/PageListView.php | 7 ------- src/Module/Admin/Tag/Form/EditForm.php | 7 ------- src/Module/Admin/Tag/Form/GridForm.php | 7 ------- src/Module/Admin/Tag/TagController.php | 7 ------- src/Module/Admin/Tag/TagEditView.php | 7 ------- src/Module/Admin/Tag/TagListView.php | 7 ------- src/Module/Admin/User/Form/EditForm.php | 7 ------- src/Module/Admin/User/Form/GridForm.php | 7 ------- src/Module/Admin/User/UserController.php | 7 ------- src/Module/Admin/User/UserEditView.php | 7 ------- src/Module/Admin/User/UserListView.php | 7 ------- src/Module/Admin/Widget/Form/EditForm.php | 7 ------- src/Module/Admin/Widget/Form/GridForm.php | 7 ------- src/Module/Admin/Widget/WidgetController.php | 7 ------- src/Module/Admin/Widget/WidgetEditView.php | 7 ------- src/Module/Admin/Widget/WidgetListView.php | 7 ------- src/Module/Core/CaptchaController.php | 7 ------- src/Module/Core/LocaleController.php | 7 ------- src/Module/Front/Article/ArticleItemView.php | 7 ------- src/Module/Front/Article/ArticleListView.php | 7 ------- src/Module/Front/Auth/AuthController.php | 7 ------- src/Module/Front/Auth/AuthLoginView.php | 7 ------- src/Module/Front/Auth/ForgetCompleteView.php | 7 ------- src/Module/Front/Auth/ForgetController.php | 7 ------- src/Module/Front/Auth/ForgetRequestView.php | 7 ------- src/Module/Front/Auth/ForgetResetView.php | 7 ------- src/Module/Front/Auth/Form/LoginForm.php | 7 ------- src/Module/Front/Auth/SocialLoginViewTrait.php | 7 ------- src/Module/Front/Auth/auth.config.php | 7 ------- src/Module/Front/Auth/forget.config.php | 7 ------- src/Module/Front/Category/CategoryViewTrait.php | 7 ------- src/Module/Front/Error/ErrorView.php | 7 ------- src/Module/Front/Page/PageController.php | 7 ------- src/Module/Front/Page/PageView.php | 7 ------- src/Module/Front/Page/page.config.php | 7 ------- src/Module/Front/Profile/Form/EditForm.php | 7 ------- src/Module/Front/Profile/ProfileController.php | 7 ------- src/Module/Front/Profile/ProfileEditView.php | 7 ------- src/Module/Front/Profile/profile.config.php | 7 ------- src/Module/Front/Registration/Form/RegistrationForm.php | 7 ------- src/Module/Front/Registration/RegistrationController.php | 7 ------- src/Module/Front/Registration/RegistrationRepository.php | 7 ------- src/Module/Front/Registration/RegistrationView.php | 7 ------- src/Module/Front/Registration/registration.config.php | 7 ------- src/PageBuilder/AbstractAddon.php | 7 ------- src/PageBuilder/Addon/Button/ButtonAddon.php | 7 ------- src/PageBuilder/Addon/Emptyspace/EmptyspaceAddon.php | 7 ------- src/PageBuilder/Addon/Feature/FeatureAddon.php | 7 ------- src/PageBuilder/Addon/Image/ImageAddon.php | 7 ------- src/PageBuilder/Addon/Text/TextAddon.php | 7 ------- src/PageBuilder/AddonType.php | 7 ------- src/PageBuilder/AdminVueComponentInterface.php | 7 ------- src/PageBuilder/HasOwnStyleInterface.php | 7 ------- src/PageBuilder/PageBuilder.php | 7 ------- src/PageBuilder/PageService.php | 7 ------- src/PageBuilder/Renderer/AbstractPageRenderer.php | 7 ------- src/PageBuilder/Renderer/AddonRenderer.php | 7 ------- src/PageBuilder/Renderer/ColumnRenderer.php | 7 ------- src/PageBuilder/Renderer/PageRendererFactory.php | 7 ------- src/PageBuilder/Renderer/PageRendererInterface.php | 7 ------- src/PageBuilder/Renderer/RowRenderer.php | 7 ------- src/PageBuilder/Renderer/Style/StyleContainer.php | 7 ------- src/PageBuilder/Renderer/Style/StyleRules.php | 7 ------- src/Repository/ArticleRepository.php | 7 ------- src/Repository/CategoryRepository.php | 7 ------- src/Repository/ConfigRepository.php | 7 ------- src/Repository/LanguageRepository.php | 7 ------- src/Repository/MenuRepository.php | 7 ------- src/Repository/PageRepository.php | 7 ------- src/Repository/TagRepository.php | 7 ------- src/Repository/UserRepository.php | 7 ------- src/Repository/WidgetRepository.php | 7 ------- src/Script/FontAwesomeScript.php | 7 ------- src/Script/LunaScript.php | 7 ------- src/Script/PageScript.php | 7 ------- src/Services/AssociationService.php | 7 ------- src/Services/ConfigService.php | 7 ------- src/Services/LocaleService.php | 7 ------- src/Services/MenuService.php | 7 ------- src/Services/TagService.php | 7 ------- src/Services/UserSwitchService.php | 7 ------- src/Subscriber/AdminSessionSubscriber.php | 7 ------- src/Subscriber/AutoOpenGraphSubscriber.php | 7 ------- src/Subscriber/BuildFormFieldSubscriber.php | 7 ------- src/Subscriber/EntityBuildingSubscriber.php | 7 ------- src/Subscriber/EntityDefaultValueSubscriber.php | 7 ------- src/Subscriber/LocaleSubscriber.php | 7 ------- src/Subscriber/RememberMeSubscriber.php | 7 ------- src/Subscriber/UserAuthSubscriber.php | 7 ------- src/Subscriber/UserSwitchSubscriber.php | 7 ------- src/Tree/Node.php | 7 ------- src/Tree/NodeInterface.php | 7 ------- src/Tree/RecursiveNodeIterator.php | 7 ------- src/Tree/TreeBuilder.php | 7 ------- src/User/ActivationService.php | 7 ------- src/User/Event/AbstractLoginEvent.php | 7 ------- src/User/Event/AfterLoginEvent.php | 7 ------- src/User/Event/AfterLoginEventTrait.php | 7 ------- src/User/Event/BeforeLoginEvent.php | 7 ------- src/User/Event/LoginAuthEvent.php | 7 ------- src/User/Event/LoginFailEvent.php | 7 ------- src/User/Exception/AccessDeniedException.php | 7 ------- src/User/Exception/AuthenticateFailException.php | 7 ------- src/User/Exception/LoginFailException.php | 7 ------- src/User/Handler/NullUserHandler.php | 7 ------- src/User/Handler/SessionDatabaseHandler.php | 7 ------- src/User/Handler/UserHandler.php | 7 ------- src/User/Handler/UserHandlerInterface.php | 7 ------- src/User/Password.php | 7 ------- src/User/PasswordInterface.php | 7 ------- src/User/UserCaster.php | 7 ------- src/User/UserEntityInterface.php | 7 ------- src/User/UserProvider.php | 7 ------- src/User/UserService.php | 7 ------- src/Widget/AbstractWidget.php | 7 ------- src/Widget/Custom/CustomHtmlWidget.php | 7 ------- src/Widget/WidgetService.php | 7 ------- src/Widget/WidgetType.php | 7 ------- src/bootstrap.php | 7 ------- src/functions.php | 7 ------- 277 files changed, 1937 deletions(-) diff --git a/bin/Console.php b/bin/Console.php index 5430e5d2..dfd4be5d 100644 --- a/bin/Console.php +++ b/bin/Console.php @@ -1,10 +1,4 @@ transORGANIZATION$this->trans. - * @license $this->transLICENSE$this->trans - */ - declare(strict_types=1); namespace Lyrasoft\Luna\Menu\View; diff --git a/src/Menu/View/RouteMenuView.php b/src/Menu/View/RouteMenuView.php index c0906ccc..ca7e5e07 100644 --- a/src/Menu/View/RouteMenuView.php +++ b/src/Menu/View/RouteMenuView.php @@ -1,12 +1,5 @@ Date: Mon, 6 Nov 2023 12:12:53 +0800 Subject: [PATCH 24/51] misc --- src/Captcha/CaptchaManager.php | 2 ++ src/Module/Front/Page/PageView.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Captcha/CaptchaManager.php b/src/Captcha/CaptchaManager.php index e1237686..d9fc0e41 100644 --- a/src/Captcha/CaptchaManager.php +++ b/src/Captcha/CaptchaManager.php @@ -12,6 +12,7 @@ namespace Lyrasoft\Luna\Captcha; use Windwalker\Core\Manager\AbstractManager; +use Windwalker\DI\Attributes\Isolation; use Windwalker\DI\Container; use Windwalker\DI\Definition\ObjectBuilderDefinition; @@ -23,6 +24,7 @@ * @method CaptchaDriverInterface create(?string $name = null, ...$args) * @method CaptchaDriverInterface get(?string $name = null, ...$args) */ +#[Isolation] class CaptchaManager extends AbstractManager { public function getConfigPrefix(): string diff --git a/src/Module/Front/Page/PageView.php b/src/Module/Front/Page/PageView.php index fae55ff4..d0c860c0 100644 --- a/src/Module/Front/Page/PageView.php +++ b/src/Module/Front/Page/PageView.php @@ -126,7 +126,7 @@ public function prepare(AppContext $app, View $view): array $previewSecret = $app->input('preview'); if ( - $page->getState()->equals(BasicState::UNPUBLISHED()) + $page->getState()->equals(BasicState::UNPUBLISHED) && (!$previewSecret || !$this->pageService->secretVerify($page->getId(), (string) $previewSecret)) ) { throw new RouteNotFoundException(); From f1e4b1f9dbd48af7105cccaee24b76762b90d0db Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 6 Nov 2023 15:42:18 +0800 Subject: [PATCH 25/51] use ts --- composer.json | 3 +- .../{article-edit.js => article-edit.ts} | 11 +--- .../assets/article-list.ts} | 7 --- .../Admin/Auth/assets/{login.js => login.ts} | 0 .../{category-edit.js => category-edit.ts} | 0 .../{category-list.js => category-list.ts} | 0 .../assets/{config-edit.js => config-edit.ts} | 0 .../assets/{config-list.js => config-list.ts} | 0 .../assets/language-edit.ts} | 7 --- .../assets/language-list.ts} | 7 --- .../assets/{menu-edit.js => menu-edit.ts} | 13 +--- .../assets/{menu-list.js => menu-list.ts} | 9 +-- src/Module/Admin/Page/assets/page-edit.js | 61 ------------------- src/Module/Admin/Page/assets/page-edit.ts | 59 ++++++++++++++++++ .../tag-list.js => Page/assets/page-list.ts} | 7 --- .../assets/tag-edit.ts} | 7 --- .../assets/tag-list.ts} | 7 --- .../assets/{user-edit.js => user-edit.ts} | 7 --- .../assets/{user-list.js => user-list.ts} | 15 ++--- .../assets/{widget-edit.js => widget-edit.ts} | 7 --- src/Module/Admin/Widget/assets/widget-list.js | 16 ----- src/Module/Admin/Widget/assets/widget-list.ts | 9 +++ .../{article-item.js => article-item.ts} | 0 .../{article-list.js => article-list.ts} | 0 ...{forget-complete.js => forget-complete.ts} | 0 .../{forget-request.js => forget-request.ts} | 0 .../{forget-reset.js => forget-reset.ts} | 0 .../Front/Auth/assets/{login.js => login.ts} | 0 .../Front/Error/assets/{error.js => error.ts} | 0 .../{profile-edit.js => profile-edit.ts} | 7 --- .../{registration.js => registration.ts} | 0 31 files changed, 80 insertions(+), 179 deletions(-) rename src/Module/Admin/Article/assets/{article-edit.js => article-edit.ts} (74%) rename src/Module/Admin/{Page/assets/page-list.js => Article/assets/article-list.ts} (58%) rename src/Module/Admin/Auth/assets/{login.js => login.ts} (100%) rename src/Module/Admin/Category/assets/{category-edit.js => category-edit.ts} (100%) rename src/Module/Admin/Category/assets/{category-list.js => category-list.ts} (100%) rename src/Module/Admin/Config/assets/{config-edit.js => config-edit.ts} (100%) rename src/Module/Admin/Config/assets/{config-list.js => config-list.ts} (100%) rename src/Module/Admin/{Tag/assets/tag-edit.js => Language/assets/language-edit.ts} (62%) rename src/Module/Admin/{Article/assets/article-list.js => Language/assets/language-list.ts} (58%) rename src/Module/Admin/Menu/assets/{menu-edit.js => menu-edit.ts} (76%) rename src/Module/Admin/Menu/assets/{menu-list.js => menu-list.ts} (69%) delete mode 100644 src/Module/Admin/Page/assets/page-edit.js create mode 100644 src/Module/Admin/Page/assets/page-edit.ts rename src/Module/Admin/{Tag/assets/tag-list.js => Page/assets/page-list.ts} (58%) rename src/Module/Admin/{Language/assets/language-edit.js => Tag/assets/tag-edit.ts} (62%) rename src/Module/Admin/{Language/assets/language-list.js => Tag/assets/tag-list.ts} (58%) rename src/Module/Admin/User/assets/{user-edit.js => user-edit.ts} (66%) rename src/Module/Admin/User/assets/{user-list.js => user-list.ts} (74%) rename src/Module/Admin/Widget/assets/{widget-edit.js => widget-edit.ts} (66%) delete mode 100644 src/Module/Admin/Widget/assets/widget-list.js create mode 100644 src/Module/Admin/Widget/assets/widget-list.ts rename src/Module/Front/Article/assets/{article-item.js => article-item.ts} (100%) rename src/Module/Front/Article/assets/{article-list.js => article-list.ts} (100%) rename src/Module/Front/Auth/assets/{forget-complete.js => forget-complete.ts} (100%) rename src/Module/Front/Auth/assets/{forget-request.js => forget-request.ts} (100%) rename src/Module/Front/Auth/assets/{forget-reset.js => forget-reset.ts} (100%) rename src/Module/Front/Auth/assets/{login.js => login.ts} (100%) rename src/Module/Front/Error/assets/{error.js => error.ts} (100%) rename src/Module/Front/Profile/assets/{profile-edit.js => profile-edit.ts} (65%) rename src/Module/Front/Registration/assets/{registration.js => registration.ts} (100%) diff --git a/composer.json b/composer.json index 82858d1b..0808e836 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "license": "MIT", "minimum-stability": "beta", "require": { - "php": ">=8.0", + "php": ">=8.2", + "windwalker/core": "^4.0", "windwalker/unicorn": "^1.0", "scssphp/scssphp": "^1.0", "symfony/polyfill-intl-idn": "^1.23", diff --git a/src/Module/Admin/Article/assets/article-edit.js b/src/Module/Admin/Article/assets/article-edit.ts similarity index 74% rename from src/Module/Admin/Article/assets/article-edit.js rename to src/Module/Admin/Article/assets/article-edit.ts index 1623a2bf..7d457436 100644 --- a/src/Module/Admin/Article/assets/article-edit.js +++ b/src/Module/Admin/Article/assets/article-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); @@ -26,10 +19,10 @@ u.$ui.tomSelect('.js-tom-select'); // Tags u.$ui.tomSelect('#input-item-tags', { - create: (input) => { + create: (input: string) => { return { value: `new#${input}`, text: input, - } + }; }, }); diff --git a/src/Module/Admin/Page/assets/page-list.js b/src/Module/Admin/Article/assets/article-list.ts similarity index 58% rename from src/Module/Admin/Page/assets/page-list.js rename to src/Module/Admin/Article/assets/article-list.ts index cd8143bb..971f9fe4 100644 --- a/src/Module/Admin/Page/assets/page-list.js +++ b/src/Module/Admin/Article/assets/article-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Auth/assets/login.js b/src/Module/Admin/Auth/assets/login.ts similarity index 100% rename from src/Module/Admin/Auth/assets/login.js rename to src/Module/Admin/Auth/assets/login.ts diff --git a/src/Module/Admin/Category/assets/category-edit.js b/src/Module/Admin/Category/assets/category-edit.ts similarity index 100% rename from src/Module/Admin/Category/assets/category-edit.js rename to src/Module/Admin/Category/assets/category-edit.ts diff --git a/src/Module/Admin/Category/assets/category-list.js b/src/Module/Admin/Category/assets/category-list.ts similarity index 100% rename from src/Module/Admin/Category/assets/category-list.js rename to src/Module/Admin/Category/assets/category-list.ts diff --git a/src/Module/Admin/Config/assets/config-edit.js b/src/Module/Admin/Config/assets/config-edit.ts similarity index 100% rename from src/Module/Admin/Config/assets/config-edit.js rename to src/Module/Admin/Config/assets/config-edit.ts diff --git a/src/Module/Admin/Config/assets/config-list.js b/src/Module/Admin/Config/assets/config-list.ts similarity index 100% rename from src/Module/Admin/Config/assets/config-list.js rename to src/Module/Admin/Config/assets/config-list.ts diff --git a/src/Module/Admin/Tag/assets/tag-edit.js b/src/Module/Admin/Language/assets/language-edit.ts similarity index 62% rename from src/Module/Admin/Tag/assets/tag-edit.js rename to src/Module/Admin/Language/assets/language-edit.ts index baaa6eb8..517ff097 100644 --- a/src/Module/Admin/Tag/assets/tag-edit.js +++ b/src/Module/Admin/Language/assets/language-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Article/assets/article-list.js b/src/Module/Admin/Language/assets/language-list.ts similarity index 58% rename from src/Module/Admin/Article/assets/article-list.js rename to src/Module/Admin/Language/assets/language-list.ts index cd8143bb..971f9fe4 100644 --- a/src/Module/Admin/Article/assets/article-list.js +++ b/src/Module/Admin/Language/assets/language-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Menu/assets/menu-edit.js b/src/Module/Admin/Menu/assets/menu-edit.ts similarity index 76% rename from src/Module/Admin/Menu/assets/menu-edit.js rename to src/Module/Admin/Menu/assets/menu-edit.ts index 36e7d262..358d950c 100644 --- a/src/Module/Admin/Menu/assets/menu-edit.js +++ b/src/Module/Admin/Menu/assets/menu-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); @@ -15,11 +8,11 @@ u.formValidation() .then(() => u.$ui.disableOnSubmit(form)); u.form(form).initComponent(); u.$ui.keepAlive(location.href); -u.$ui.tomSelect('.js-tom-select') +u.$ui.tomSelect('.js-tom-select'); // Menu control const currentType = u.data('current.type'); -const typeField = u.selectOne('#input-item-type'); +const typeField = u.selectOne('#input-item-type')!; typeField.addEventListener('change', (e) => { if (typeField.value !== '' && typeField.value !== currentType) { @@ -31,7 +24,7 @@ typeField.addEventListener('change', (e) => { }); const currentView = u.data('current.view'); -const viewField = u.selectOne('#input-item-view'); +const viewField = u.selectOne('#input-item-view')!; viewField.addEventListener('change', (e) => { if (viewField.value !== '' && viewField.value !== currentView) { diff --git a/src/Module/Admin/Menu/assets/menu-list.js b/src/Module/Admin/Menu/assets/menu-list.ts similarity index 69% rename from src/Module/Admin/Menu/assets/menu-list.js rename to src/Module/Admin/Menu/assets/menu-list.ts index 2b6efc98..9f18d80c 100644 --- a/src/Module/Admin/Menu/assets/menu-list.js +++ b/src/Module/Admin/Menu/assets/menu-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); @@ -18,7 +11,7 @@ u.$ui.checkboxesMultiSelect(form); // Switch type const route = u.route('self'); -const typeField = u.selectOne('#input-type'); +const typeField = u.selectOne('#input-type')!; typeField.addEventListener('change', () => { const type = typeField.value; diff --git a/src/Module/Admin/Page/assets/page-edit.js b/src/Module/Admin/Page/assets/page-edit.js deleted file mode 100644 index fe8f6a70..00000000 --- a/src/Module/Admin/Page/assets/page-edit.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - -import '@main'; - -u.$ui.bootstrap.tooltip(); - -const form = '#admin-form'; - -u.formValidation(form) - .then(validateOptionsModal) - .then(() => u.$ui.disableOnSubmit(form)); -u.form(form).initComponent(); -u.$ui.keepAlive(location.href); - -// Auto open options -const url = new URL(location.href); -const titleInput = u.selectOne('#input-item-title'); -const aliasInput = u.selectOne('#input-item-alias'); - -if (url.searchParams.get('new') === '1' || titleInput.value === '') { - const modal = u.$ui.bootstrap.modal('#options-modal'); - - aliasInput.value = ''; - - modal.show(); - - setTimeout(() => { - titleInput.focus(); - }, 300); -} - -// Validate options -function validateOptionsModal(validation) { - const modal = u.selectOne('#options-modal'); - - modal.addEventListener('hide.bs.modal', (e) => { - const result = validation.validateAll(modal.querySelectorAll('[uni-field-validate]')); - - if (!result) { - e.stopPropagation(); - e.preventDefault(); - } - }); -} - -// Change alias path value -document.getElementById('js-save-button').onclick = function () { - const link = document.querySelector('.js-preview-button').href; - const value = document.querySelector('#input-item-alias').value; - const pre = link.split('page/'); - const next = pre[1].split('?'); - - if (next[0] !== value) { - document.querySelector('.js-preview-button').href = pre[0] + 'page/' + value + '?' + next[1]; - } -} diff --git a/src/Module/Admin/Page/assets/page-edit.ts b/src/Module/Admin/Page/assets/page-edit.ts new file mode 100644 index 00000000..3c878eb7 --- /dev/null +++ b/src/Module/Admin/Page/assets/page-edit.ts @@ -0,0 +1,59 @@ +import '@main'; + +u.$ui.bootstrap.tooltip(); + +const form = '#admin-form'; + +u.formValidation(form) + .then(validateOptionsModal) + .then(() => u.$ui.disableOnSubmit(form)); +u.form(form).initComponent(); +u.$ui.keepAlive(location.href); + +// Auto open options +const url = new URL(location.href); +const titleInput = u.selectOne('#input-item-title')!; +const aliasInput = u.selectOne('#input-item-alias')!; + +if (url.searchParams.get('new') === '1' || titleInput.value === '') { + const modal = u.$ui.bootstrap.modal('#options-modal'); + + aliasInput.value = ''; + + modal.show(); + + setTimeout(() => { + titleInput.focus(); + }, 300); +} + +// Validate options +function validateOptionsModal(validation: Awaited>) { + const modal = u.selectOne('#options-modal')!; + + modal.addEventListener('hide.bs.modal', (e) => { + const result = validation!.validateAll( + u.selectAll(modal.querySelectorAll('[uni-field-validate]')) + ); + + if (!result) { + e.stopPropagation(); + e.preventDefault(); + } + }); +} + +// Change alias path value +document.getElementById('js-save-button') + ?.addEventListener('click', () => { + const button = document.querySelector('.js-preview-button')!; + + const link = button.href; + const value = document.querySelector('#input-item-alias')!.value; + const pre = link.split('page/'); + const next = pre[1].split('?'); + + if (next[0] !== value) { + button.href = pre[0] + 'page/' + value + '?' + next[1]; + } + }); diff --git a/src/Module/Admin/Tag/assets/tag-list.js b/src/Module/Admin/Page/assets/page-list.ts similarity index 58% rename from src/Module/Admin/Tag/assets/tag-list.js rename to src/Module/Admin/Page/assets/page-list.ts index cd8143bb..971f9fe4 100644 --- a/src/Module/Admin/Tag/assets/tag-list.js +++ b/src/Module/Admin/Page/assets/page-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Language/assets/language-edit.js b/src/Module/Admin/Tag/assets/tag-edit.ts similarity index 62% rename from src/Module/Admin/Language/assets/language-edit.js rename to src/Module/Admin/Tag/assets/tag-edit.ts index baaa6eb8..517ff097 100644 --- a/src/Module/Admin/Language/assets/language-edit.js +++ b/src/Module/Admin/Tag/assets/tag-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Language/assets/language-list.js b/src/Module/Admin/Tag/assets/tag-list.ts similarity index 58% rename from src/Module/Admin/Language/assets/language-list.js rename to src/Module/Admin/Tag/assets/tag-list.ts index cd8143bb..971f9fe4 100644 --- a/src/Module/Admin/Language/assets/language-list.js +++ b/src/Module/Admin/Tag/assets/tag-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/User/assets/user-edit.js b/src/Module/Admin/User/assets/user-edit.ts similarity index 66% rename from src/Module/Admin/User/assets/user-edit.js rename to src/Module/Admin/User/assets/user-edit.ts index a974d7ff..649652c5 100644 --- a/src/Module/Admin/User/assets/user-edit.js +++ b/src/Module/Admin/User/assets/user-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/User/assets/user-list.js b/src/Module/Admin/User/assets/user-list.ts similarity index 74% rename from src/Module/Admin/User/assets/user-list.js rename to src/Module/Admin/User/assets/user-list.ts index 88e94700..53a536fb 100644 --- a/src/Module/Admin/User/assets/user-list.js +++ b/src/Module/Admin/User/assets/user-list.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); @@ -16,8 +9,8 @@ u.$ui.disableOnSubmit(form); u.$ui.checkboxesMultiSelect(form); // User Switch -const $modal = document.querySelector('#user-switch-modal'); -const $switchUserId = $modal?.querySelector('[data-role=user_id]'); +const $modal = document.querySelector('#user-switch-modal')!; +const $switchUserId = $modal.querySelector('[data-role=user_id]')!; $modal?.addEventListener('hidden.bs.modal', () => { $switchUserId.value = ''; @@ -29,7 +22,7 @@ u.directive('user-switch-button', { el.addEventListener('click', () => { u.$ui.bootstrap.modal($modal).show(); $switchUserId.value = value.id; - $modal.querySelector('[data-role=user_name]').textContent = value.name; + $modal.querySelector('[data-role=user_name]')!.textContent = value.name; }); }, updated(el, bindings) { @@ -41,7 +34,7 @@ u.directive('user-switch-modal', { mounted(el, { value }) { u.selectAll('[data-role=switch_button]', ($btn) => { $btn.addEventListener('click', (e) => { - const $btn = e.currentTarget; + const $btn = e.currentTarget as HTMLButtonElement; const stage = $btn.dataset.stage; const options = JSON.parse($btn.dataset.options || '{}'); diff --git a/src/Module/Admin/Widget/assets/widget-edit.js b/src/Module/Admin/Widget/assets/widget-edit.ts similarity index 66% rename from src/Module/Admin/Widget/assets/widget-edit.js rename to src/Module/Admin/Widget/assets/widget-edit.ts index 9cb47f8e..db4c7eb6 100644 --- a/src/Module/Admin/Widget/assets/widget-edit.js +++ b/src/Module/Admin/Widget/assets/widget-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Admin/Widget/assets/widget-list.js b/src/Module/Admin/Widget/assets/widget-list.js deleted file mode 100644 index cd8143bb..00000000 --- a/src/Module/Admin/Widget/assets/widget-list.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - -import '@main'; - -u.$ui.bootstrap.tooltip(); - -const form = '#admin-form'; - -u.grid(form).initComponent(); -u.$ui.disableOnSubmit(form); -u.$ui.checkboxesMultiSelect(form); diff --git a/src/Module/Admin/Widget/assets/widget-list.ts b/src/Module/Admin/Widget/assets/widget-list.ts new file mode 100644 index 00000000..971f9fe4 --- /dev/null +++ b/src/Module/Admin/Widget/assets/widget-list.ts @@ -0,0 +1,9 @@ +import '@main'; + +u.$ui.bootstrap.tooltip(); + +const form = '#admin-form'; + +u.grid(form).initComponent(); +u.$ui.disableOnSubmit(form); +u.$ui.checkboxesMultiSelect(form); diff --git a/src/Module/Front/Article/assets/article-item.js b/src/Module/Front/Article/assets/article-item.ts similarity index 100% rename from src/Module/Front/Article/assets/article-item.js rename to src/Module/Front/Article/assets/article-item.ts diff --git a/src/Module/Front/Article/assets/article-list.js b/src/Module/Front/Article/assets/article-list.ts similarity index 100% rename from src/Module/Front/Article/assets/article-list.js rename to src/Module/Front/Article/assets/article-list.ts diff --git a/src/Module/Front/Auth/assets/forget-complete.js b/src/Module/Front/Auth/assets/forget-complete.ts similarity index 100% rename from src/Module/Front/Auth/assets/forget-complete.js rename to src/Module/Front/Auth/assets/forget-complete.ts diff --git a/src/Module/Front/Auth/assets/forget-request.js b/src/Module/Front/Auth/assets/forget-request.ts similarity index 100% rename from src/Module/Front/Auth/assets/forget-request.js rename to src/Module/Front/Auth/assets/forget-request.ts diff --git a/src/Module/Front/Auth/assets/forget-reset.js b/src/Module/Front/Auth/assets/forget-reset.ts similarity index 100% rename from src/Module/Front/Auth/assets/forget-reset.js rename to src/Module/Front/Auth/assets/forget-reset.ts diff --git a/src/Module/Front/Auth/assets/login.js b/src/Module/Front/Auth/assets/login.ts similarity index 100% rename from src/Module/Front/Auth/assets/login.js rename to src/Module/Front/Auth/assets/login.ts diff --git a/src/Module/Front/Error/assets/error.js b/src/Module/Front/Error/assets/error.ts similarity index 100% rename from src/Module/Front/Error/assets/error.js rename to src/Module/Front/Error/assets/error.ts diff --git a/src/Module/Front/Profile/assets/profile-edit.js b/src/Module/Front/Profile/assets/profile-edit.ts similarity index 65% rename from src/Module/Front/Profile/assets/profile-edit.js rename to src/Module/Front/Profile/assets/profile-edit.ts index d644c755..705d9fb7 100644 --- a/src/Module/Front/Profile/assets/profile-edit.js +++ b/src/Module/Front/Profile/assets/profile-edit.ts @@ -1,10 +1,3 @@ -/** - * Part of starter project. - * - * @copyright Copyright (C) 2021 __ORGANIZATION__. - * @license __LICENSE__ - */ - import '@main'; u.$ui.bootstrap.tooltip(); diff --git a/src/Module/Front/Registration/assets/registration.js b/src/Module/Front/Registration/assets/registration.ts similarity index 100% rename from src/Module/Front/Registration/assets/registration.js rename to src/Module/Front/Registration/assets/registration.ts From 49d64dfb09b6ff138f9c3f64c47f86fbfd7d9d0e Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Tue, 7 Nov 2023 22:04:57 +0800 Subject: [PATCH 26/51] misc --- src/Module/Admin/Article/Form/EditForm.php | 149 ++++++++++---------- src/Subscriber/EntityBuildingSubscriber.php | 74 ---------- 2 files changed, 71 insertions(+), 152 deletions(-) diff --git a/src/Module/Admin/Article/Form/EditForm.php b/src/Module/Admin/Article/Form/EditForm.php index 8a6857dc..3cf82405 100644 --- a/src/Module/Admin/Article/Form/EditForm.php +++ b/src/Module/Admin/Article/Form/EditForm.php @@ -17,15 +17,14 @@ use Unicorn\Field\SwitcherField; use Unicorn\Field\TinymceEditorField; use Windwalker\Core\Language\TranslatorTrait; +use Windwalker\Form\Attributes\Fieldset; +use Windwalker\Form\Attributes\FormDefine; use Windwalker\Form\Field\HiddenField; use Windwalker\Form\Field\TextField; use Windwalker\Form\FieldDefinitionInterface; use Windwalker\Form\Form; -/** - * The EditForm class. - */ -class EditForm implements FieldDefinitionInterface +class EditForm { use TranslatorTrait; use LocaleAwareTrait; @@ -34,14 +33,8 @@ public function __construct(protected ?string $type = 'article') { } - /** - * Define the form fields. - * - * @param Form $form The Windwalker form object. - * - * @return void - */ - public function define(Form $form): void + #[FormDefine] + public function main(Form $form): void { $form->add('title', TextField::class) ->label($this->trans('unicorn.field.title')) @@ -52,72 +45,6 @@ public function define(Form $form): void ->label($this->trans('unicorn.field.alias')) ->addFilter('trim'); - $form->fieldset( - 'text', - function (Form $form) { - $form->add('introtext', TinymceEditorField::class) - ->label($this->trans('luna.article.field.introtext')) - ->editorOptions( - [ - 'height' => 400, - ] - ); - - $form->add('fulltext', TinymceEditorField::class) - ->label($this->trans('luna.article.field.fulltext')) - ->rows(7) - ->editorOptions( - [ - 'height' => 550, - ] - ); - } - ); - - $form->fieldset( - 'meta', - function (Form $form) { - $form->add('category_id', CategoryListField::class) - ->label($this->trans('luna.article.field.category')) - ->categoryType($this->type); - - $form->add('tags', TagListField::class) - ->label($this->trans('luna.article.field.tags')) - ->multiple(true); - - $form->add('page_id', PageModalField::class) - ->label($this->trans('luna.article.field.page')); - - $form->add('image', SingleImageDragField::class) - ->label($this->trans('unicorn.field.image')) - ->crop(true) - ->width(800) - ->height(600); - - $form->add('state', SwitcherField::class) - ->label($this->trans('unicorn.field.published')) - ->circle(true) - ->color('success'); - - $form->add('created', CalendarField::class) - ->label($this->trans('unicorn.field.created')); - - $form->add('modified', CalendarField::class) - ->label($this->trans('unicorn.field.modified')) - ->disabled(true); - - $form->add('created_by', UserModalField::class) - ->label($this->trans('unicorn.field.author')); - - $form->add('modified_by', UserModalField::class) - ->label($this->trans('unicorn.field.modified_by')) - ->disabled(true); - - $form->add('type', HiddenField::class) - ->label('Type'); - } - ); - $form->add('id', HiddenField::class); if ($this->isLocaleEnabled()) { @@ -128,4 +55,70 @@ function (Form $form) { ->allowCreateEmpty(true); } } + + #[FormDefine] + #[Fieldset('text')] + public function text(Form $form): void + { + $form->add('introtext', TinymceEditorField::class) + ->label($this->trans('luna.article.field.introtext')) + ->editorOptions( + [ + 'height' => 400, + ] + ); + + $form->add('fulltext', TinymceEditorField::class) + ->label($this->trans('luna.article.field.fulltext')) + ->rows(7) + ->editorOptions( + [ + 'height' => 550, + ] + ); + } + + #[FormDefine] + #[Fieldset('meta')] + public function meta(Form $form): void + { + $form->add('category_id', CategoryListField::class) + ->label($this->trans('luna.article.field.category')) + ->categoryType($this->type); + + $form->add('tags', TagListField::class) + ->label($this->trans('luna.article.field.tags')) + ->multiple(true); + + $form->add('page_id', PageModalField::class) + ->label($this->trans('luna.article.field.page')); + + $form->add('image', SingleImageDragField::class) + ->label($this->trans('unicorn.field.image')) + ->crop(true) + ->width(800) + ->height(600); + + $form->add('state', SwitcherField::class) + ->label($this->trans('unicorn.field.published')) + ->circle(true) + ->color('success'); + + $form->add('created', CalendarField::class) + ->label($this->trans('unicorn.field.created')); + + $form->add('modified', CalendarField::class) + ->label($this->trans('unicorn.field.modified')) + ->disabled(true); + + $form->add('created_by', UserModalField::class) + ->label($this->trans('unicorn.field.author')); + + $form->add('modified_by', UserModalField::class) + ->label($this->trans('unicorn.field.modified_by')) + ->disabled(true); + + $form->add('type', HiddenField::class) + ->label('Type'); + } } diff --git a/src/Subscriber/EntityBuildingSubscriber.php b/src/Subscriber/EntityBuildingSubscriber.php index f4e65926..3bd187d0 100644 --- a/src/Subscriber/EntityBuildingSubscriber.php +++ b/src/Subscriber/EntityBuildingSubscriber.php @@ -7,17 +7,12 @@ use Lyrasoft\Luna\Attributes\Author; use Lyrasoft\Luna\Attributes\Modifier; use Lyrasoft\Luna\Attributes\Slugify; -use MyCLabs\Enum\Enum; -use PhpParser\Node; use Symfony\Component\OptionsResolver\OptionsResolver; -use Unicorn\Attributes\OrderLast; -use Windwalker\Core\Generator\Event\BuildEntityMethodEvent; use Windwalker\Core\Generator\Event\BuildEntityPropertyEvent; use Windwalker\Event\Attributes\EventSubscriber; use Windwalker\Event\Attributes\ListenTo; use Windwalker\ORM\Attributes\CreatedTime; use Windwalker\ORM\Attributes\CurrentTime; -use Windwalker\Utilities\Enum\EnumMetaInterface; use Windwalker\Utilities\Options\OptionsResolverTrait; /** @@ -107,73 +102,4 @@ public function buildEntityProperty(BuildEntityPropertyEvent $event): void ); } } - - #[ListenTo(BuildEntityMethodEvent::class)] - public function buildMethod(BuildEntityMethodEvent $event): void - { - $builder = $event->getEntityMemberBuilder(); - $method = $event->getMethod(); - $propName = $event->getPropName(); - $column = $event->getColumn(); - $shortName = $event->getTypeName(); - - $factory = $builder->createNodeFactory(); - - if ($event->isSetter()) { - $className = $builder->findFQCN($shortName); - - // Enum can set pure value - if ($className && class_exists($className) && $this->isEnum($className)) { - if ($column) { - $subType = $column->isNumeric() ? 'int' : 'string'; - } else { - $subType = 'int|string'; - } - - $subType .= '|' . $shortName; - - $method->params[0] = $factory->param($propName) - ->setType($subType) - ->getNode(); - - if (is_a($className, EnumMetaInterface::class, true)) { - $enum = $factory->staticCall( - new Node\Name($shortName), - 'wrap', - [ - new Node\Expr\Variable($propName), - ] - ); - } else { - $enum = $factory->new( - new Node\Name($shortName), - [ - new Node\Expr\Variable($propName), - ] - ); - } - - $method->stmts[0] = new Node\Stmt\Expression( - new Node\Expr\Assign( - $factory->propertyFetch( - new Node\Expr\Variable('this'), - $propName - ), - $enum - ) - ); - } - } - } - - /** - * @param string $className - * - * @return bool - */ - protected function isEnum(string $className): bool - { - return is_a($className, Enum::class, true) - || is_a($className, \UnitEnum::class, true); - } } From 0e54e28253ff93dfcfec02f9a756de4b9b2a8e6f Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Wed, 8 Nov 2023 16:08:18 +0800 Subject: [PATCH 27/51] server time --- src/Entity/Article.php | 5 +++-- src/Entity/Category.php | 5 +++-- src/Entity/Config.php | 3 ++- src/Entity/Menu.php | 5 +++-- src/Entity/Page.php | 5 +++-- src/Entity/PageTemplate.php | 5 +++-- src/Entity/Tag.php | 5 +++-- src/Entity/User.php | 9 +++++---- src/Entity/UserRole.php | 5 +++-- src/Entity/Widget.php | 5 +++-- 10 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/Entity/Article.php b/src/Entity/Article.php index 844a37fc..d8dbfcec 100644 --- a/src/Entity/Article.php +++ b/src/Entity/Article.php @@ -10,6 +10,7 @@ use Lyrasoft\Luna\Attributes\Slugify; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -76,12 +77,12 @@ class Article implements EntityInterface #[Column('created')] #[CreatedTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $created = null; #[Column('modified')] #[CurrentTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $modified = null; #[Column('created_by')] diff --git a/src/Entity/Category.php b/src/Entity/Category.php index c9d0ba28..7838c6ff 100644 --- a/src/Entity/Category.php +++ b/src/Entity/Category.php @@ -10,6 +10,7 @@ use Lyrasoft\Luna\Attributes\Slugify; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -61,12 +62,12 @@ class Category implements NestedPathableInterface #[Column('created')] #[CreatedTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $created = null; #[Column('modified')] #[CurrentTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $modified = null; #[Column('created_by')] diff --git a/src/Entity/Config.php b/src/Entity/Config.php index b3d6dd72..a8f12ba0 100644 --- a/src/Entity/Config.php +++ b/src/Entity/Config.php @@ -6,6 +6,7 @@ use DateTimeInterface; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; use Windwalker\ORM\Attributes\Column; @@ -39,7 +40,7 @@ class Config implements EntityInterface #[Column('modified')] #[CurrentTime('now', false)] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $modified = null; #[Column('modified_by')] diff --git a/src/Entity/Menu.php b/src/Entity/Menu.php index 48f28978..8ee638d7 100644 --- a/src/Entity/Menu.php +++ b/src/Entity/Menu.php @@ -10,6 +10,7 @@ use Lyrasoft\Luna\Enum\MenuTarget; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -69,12 +70,12 @@ class Menu implements NestedEntityInterface protected bool $hidden = false; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; diff --git a/src/Entity/Page.php b/src/Entity/Page.php index a4c678aa..d06634f7 100644 --- a/src/Entity/Page.php +++ b/src/Entity/Page.php @@ -11,6 +11,7 @@ use Lyrasoft\Luna\Data\MetaData; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -73,7 +74,7 @@ class Page implements EntityInterface protected int $ordering = 0; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; @@ -82,7 +83,7 @@ class Page implements EntityInterface protected int $createdBy = 0; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; diff --git a/src/Entity/PageTemplate.php b/src/Entity/PageTemplate.php index adbe3da2..eb2c9aae 100644 --- a/src/Entity/PageTemplate.php +++ b/src/Entity/PageTemplate.php @@ -8,6 +8,7 @@ use Lyrasoft\Luna\Attributes\Author; use Lyrasoft\Luna\Attributes\Modifier; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -51,7 +52,7 @@ class PageTemplate implements EntityInterface protected array $content = []; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; @@ -60,7 +61,7 @@ class PageTemplate implements EntityInterface protected int $createdBy = 0; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 1beddca7..c84cfce3 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -10,6 +10,7 @@ use Lyrasoft\Luna\Attributes\Slugify; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -50,12 +51,12 @@ class Tag implements EntityInterface protected BasicState $state; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; diff --git a/src/Entity/User.php b/src/Entity/User.php index 99e339c7..f4a1f265 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -7,6 +7,7 @@ use DateTimeInterface; use Lyrasoft\Luna\User\UserEntityInterface; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -68,21 +69,21 @@ class User implements EntityInterface, UserEntityInterface protected string $resetToken = ''; #[Column('last_reset')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $lastReset = null; #[Column('last_login')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $lastLogin = null; #[Column('registered')] #[CreatedTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $registered = null; #[Column('modified')] #[CurrentTime] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] protected ?Chronos $modified = null; #[Column('params')] diff --git a/src/Entity/UserRole.php b/src/Entity/UserRole.php index a7a20c48..b2cf4d11 100644 --- a/src/Entity/UserRole.php +++ b/src/Entity/UserRole.php @@ -9,6 +9,7 @@ use Lyrasoft\Luna\Attributes\Modifier; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -47,12 +48,12 @@ class UserRole implements NestedEntityInterface protected BasicState $state; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; diff --git a/src/Entity/Widget.php b/src/Entity/Widget.php index 7b318726..fe9df439 100644 --- a/src/Entity/Widget.php +++ b/src/Entity/Widget.php @@ -8,6 +8,7 @@ use Lyrasoft\Luna\Attributes\Modifier; use Unicorn\Enum\BasicState; use Windwalker\Core\DateTime\Chronos; +use Windwalker\Core\DateTime\ServerTimeCast; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -58,7 +59,7 @@ class Widget implements EntityInterface protected int $ordering = 0; #[Column('created')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CreatedTime] protected ?Chronos $created = null; @@ -67,7 +68,7 @@ class Widget implements EntityInterface protected int $createdBy = 0; #[Column('modified')] - #[CastNullable(Chronos::class)] + #[CastNullable(ServerTimeCast::class)] #[CurrentTime] protected ?Chronos $modified = null; From 7cb9837e927ccbf455ffc434162684ca0a22ab7c Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 9 Nov 2023 02:28:24 +0800 Subject: [PATCH 28/51] misc --- composer.json | 9 ++++++--- src/Module/Admin/Page/views/page-list.blade.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0808e836..bc266be6 100644 --- a/composer.json +++ b/composer.json @@ -36,9 +36,12 @@ "modules": [ "src/Module" ], - "asset_vendors": [ - "codemirror" - ] + "assets": { + "vendors": { + "codemirror": "^5.63.3" + }, + "link": "assets/" + } }, "branch-alias": { "dev-master": "2.x-dev", diff --git a/src/Module/Admin/Page/views/page-list.blade.php b/src/Module/Admin/Page/views/page-list.blade.php index e555d64a..6da842f0 100644 --- a/src/Module/Admin/Page/views/page-list.blade.php +++ b/src/Module/Admin/Page/views/page-list.blade.php @@ -125,7 +125,7 @@ >
- {{ $item->category->title ?: '-' }} + {{ $item->category?->title ?: '-' }}
From 8d9931d5c39639b5eaa1e08556022e289d93d7d1 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 11 Nov 2023 02:35:31 +0800 Subject: [PATCH 29/51] composer --- composer.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index bc266be6..d69909df 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "minimum-stability": "beta", "require": { "php": ">=8.2", - "windwalker/core": "^4.0", - "windwalker/unicorn": "^1.0", + "windwalker/core": "^4.1", + "windwalker/unicorn": "^1.1", "scssphp/scssphp": "^1.0", "symfony/polyfill-intl-idn": "^1.23", "firebase/php-jwt": "^5.4||^6.0" @@ -44,8 +44,7 @@ } }, "branch-alias": { - "dev-master": "2.x-dev", - "dev-next": "2.1.x-dev" + "dev-master": "2.x-dev" } } } From 8f9c8719259d7cdfcf071a987d1e987cf97c581b Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sat, 11 Nov 2023 22:45:36 +0800 Subject: [PATCH 30/51] srp wip --- routes/front/auth.route.php | 3 + src/Auth/SRPAuthMethod.php | 19 +++++ src/Auth/SrpService.php | 36 +++++++++ src/Entity/User.php | 8 ++ src/LunaPackage.php | 2 + src/Module/Admin/User/Form/EditForm.php | 2 + src/Module/Front/Auth/AuthController.php | 35 ++++++++- src/Module/Front/Auth/Form/LoginForm.php | 3 + src/Module/Front/Auth/assets/login.ts | 82 +++++++++++++++++++++ src/Module/Front/Auth/views/login.blade.php | 22 +++--- 10 files changed, 202 insertions(+), 10 deletions(-) create mode 100644 src/Auth/SRPAuthMethod.php create mode 100644 src/Auth/SrpService.php diff --git a/routes/front/auth.route.php b/routes/front/auth.route.php index 3a9da06f..d7190158 100644 --- a/routes/front/auth.route.php +++ b/routes/front/auth.route.php @@ -26,6 +26,9 @@ function (RouteCreator $router) { $router->any('logout', '/logout') ->controller(AuthController::class, 'logout'); + $router->any('auth_ajax', '/auth/ajax') + ->controller(AuthController::class, 'ajax'); + // Registration $router->any('registration', '/registration') ->postHandler(AuthController::class, 'register') diff --git a/src/Auth/SRPAuthMethod.php b/src/Auth/SRPAuthMethod.php new file mode 100644 index 00000000..5296a1d2 --- /dev/null +++ b/src/Auth/SRPAuthMethod.php @@ -0,0 +1,19 @@ +session->set('srp.public.client', $public); + } + + public function generateRandomSeed(int $length = SECRET_128BIT): string + { + return SecretToolkit::genSecret($length, ENCODER_HEX); + } + + public function generatePublicEphemeral(string $seed, #[\SensitiveParameter] string $userSecret): string + { + + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index f4a1f265..7ff1497e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -8,6 +8,8 @@ use Lyrasoft\Luna\User\UserEntityInterface; use Windwalker\Core\DateTime\Chronos; use Windwalker\Core\DateTime\ServerTimeCast; +use Windwalker\Crypt\SecretToolkit; +use Windwalker\Data\Collection; use Windwalker\ORM\Attributes\AutoIncrement; use Windwalker\ORM\Attributes\Cast; use Windwalker\ORM\Attributes\CastNullable; @@ -104,6 +106,12 @@ public static function beforeSave(BeforeSaveEvent $event): void if (isset($data['password']) && $data['password'] === '') { unset($data['password']); } + + $params = &$data['params']; + $params = Collection::from($params ?: '{}', 'json'); + $params['srp_secret'] = SecretToolkit::genSecret(); + + $params = $params->dump(); } /** diff --git a/src/LunaPackage.php b/src/LunaPackage.php index ec0aaf24..c79ddae8 100644 --- a/src/LunaPackage.php +++ b/src/LunaPackage.php @@ -7,6 +7,7 @@ use Lyrasoft\Luna\Access\AccessAuthorization; use Lyrasoft\Luna\Access\AccessService; use Lyrasoft\Luna\Auth\SocialAuthService; +use Lyrasoft\Luna\Auth\SrpService; use Lyrasoft\Luna\Captcha\CaptchaManager; use Lyrasoft\Luna\Error\LunaErrorHandler; use Lyrasoft\Luna\Faker\LunaFakerProvider; @@ -74,6 +75,7 @@ public function register(Container $container): void $container->prepareSharedObject(LocaleService::class); $container->prepareSharedObject(WidgetService::class); $container->prepareSharedObject(AssociationService::class); + $container->prepareSharedObject(SrpService::class); $this->registerAuthServices($container); diff --git a/src/Module/Admin/User/Form/EditForm.php b/src/Module/Admin/User/Form/EditForm.php index 19eb263b..b9c350cb 100644 --- a/src/Module/Admin/User/Form/EditForm.php +++ b/src/Module/Admin/User/Form/EditForm.php @@ -55,12 +55,14 @@ function (Form $form) use ($loginName) { if ($loginName !== 'email') { $form->add($loginName, TextField::class) ->label($this->trans('luna.user.field.' . $loginName)) + ->attr('data-username', true) ->required(true) ->addFilter('trim'); } $form->add('email', EmailField::class) ->label($this->trans('luna.user.field.email')) + ->attr('data-username', $loginName === 'email') ->required(true) ->addFilter('trim') ->addValidator(EmailAddress::class); diff --git a/src/Module/Front/Auth/AuthController.php b/src/Module/Front/Auth/AuthController.php index 0646e8c3..893f802b 100644 --- a/src/Module/Front/Auth/AuthController.php +++ b/src/Module/Front/Auth/AuthController.php @@ -6,23 +6,26 @@ use Lyrasoft\Luna\Access\AccessService; use Lyrasoft\Luna\Auth\SocialAuthService; +use Lyrasoft\Luna\Auth\SrpService; use Lyrasoft\Luna\Entity\User; use Lyrasoft\Luna\LunaPackage; use Lyrasoft\Luna\Module\Front\Registration\Form\RegistrationForm; use Lyrasoft\Luna\Module\Front\Registration\RegistrationRepository; use Lyrasoft\Luna\User\ActivationService; use Lyrasoft\Luna\User\UserService; +use Unicorn\Attributes\Ajax; +use Unicorn\Controller\AjaxControllerTrait; use Windwalker\Authentication\AuthResult; use Windwalker\Authentication\ResultSet; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Attributes\Controller; use Windwalker\Core\Attributes\JsonApi; -use Windwalker\Core\Attributes\Ref; use Windwalker\Core\Attributes\TaskMapping; use Windwalker\Core\Language\TranslatorTrait; use Windwalker\Core\Router\Navigator; use Windwalker\Core\Router\RouteUri; use Windwalker\Core\Utilities\Base64Url; +use Windwalker\Crypt\SecretToolkit; use Windwalker\DI\Attributes\Autowire; use Windwalker\ORM\ORM; @@ -42,6 +45,7 @@ class AuthController { use TranslatorTrait; + use AjaxControllerTrait; public function login(AppContext $app, UserService $userService, Navigator $nav, ORM $orm): RouteUri { @@ -127,6 +131,7 @@ public function register( $user = $repository->register($user, RegistrationForm::class); } catch (\Throwable $e) { $app->addMessage($e->getMessage(), 'warning'); + return $nav->to('registration'); } @@ -229,4 +234,32 @@ public function socialAuth( return $nav->to('home'); } + + #[Ajax] + public function challenge( + AppContext $app, + LunaPackage $luna, + UserService $userService, + SrpService $srpService, + ) { + [$username, $public] = $app->input('seed', 'public'); + + $srpService->storeClientPublicEphemeral($public); + + $loginName = $luna->getLoginName(); + + /** @var User $user */ + $user = $userService->load([$loginName => $username]); + + if (!$user) { + throw new \RuntimeException('User not found.'); + } + + $secret = $user->getParams()['srp_secret'] ?? ''; + + $seed = $srpService->generateRandomSeed(); + $public = $srpService->generatePublicEphemeral($seed, SecretToolkit::decode($secret)); + + return compact('seed', 'public'); + } } diff --git a/src/Module/Front/Auth/Form/LoginForm.php b/src/Module/Front/Auth/Form/LoginForm.php index a0873b7c..167cc7f0 100644 --- a/src/Module/Front/Auth/Form/LoginForm.php +++ b/src/Module/Front/Auth/Form/LoginForm.php @@ -36,15 +36,18 @@ public function define(Form $form): void if ($loginName === 'email') { $form->add('email', EmailField::class) ->label($this->trans('user.field.email')) + ->attr('data-username', true) ->required(true); } else { $form->add($loginName, TextField::class) ->label($this->trans('user.field.' . $loginName)) + ->attr('data-username', true) ->required(true); } $form->add('password', PasswordField::class) ->label($this->trans('user.field.password')) + ->attr('data-password', true) ->required(true); }); } diff --git a/src/Module/Front/Auth/assets/login.ts b/src/Module/Front/Auth/assets/login.ts index e973cad5..fb065997 100644 --- a/src/Module/Front/Auth/assets/login.ts +++ b/src/Module/Front/Auth/assets/login.ts @@ -7,3 +7,85 @@ u.formValidation() u.$ui.disableOnSubmit('#login-form'); u.$ui.disableOnSubmit('#login-form-extra'); }); + +const loginButton = u.selectOne('.c-login-button')!; +const usernameInput = u.selectOne('[data-username]')!; +const passwordInput = u.selectOne('[data-password]')!; + +const form = passwordInput.form!; +const overridePasswordInput = u.html(``); + +form.appendChild(overridePasswordInput); + +class SRP { + generateRandomSeed(length = 32) { + return u.$crypto.randomString(length); + } + + generatePublicEphemeral(seed: string, username: string, password: string) { + const bint = this.hexToBigInt(seed); + + const bintStr = bint.toString(); + + return this.hash(bintStr + this.hash(username + ":" + password)); + } + + generateRandomBigInt(length: number) { + const hexString = Array(length) + .fill(undefined) + .map(() => Math.round(Math.random() * 0xF).toString(16)) + .join(''); + + return BigInt(`0x${hexString}`); + } + + generatePrivateKey(seed: string, username: string, password: string) { + const bint = this.hexToBigInt(seed); + + const bintStr = bint.toString(); + + return this.hash(bintStr + this.hash(username + ":" + password)); + } + + hexToBigInt(hex: string) { + if (hex.length % 2) { + hex = '0' + hex; + } + + return BigInt('0x' + hex); + } + + async hash(message: string) { + const msgBuffer = new TextEncoder().encode(message); + const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + } +} + +const srp = new SRP(); + +(window as any).srp = srp; + +loginButton.addEventListener('click', async (e) => { + e.preventDefault(); + + loginButton.disabled = true; + + // Generate seed + const seed = srp.generateRandomSeed(); + + // Generate Public ephemeral + const x = await srp.generatePublicEphemeral( + seed, + usernameInput.value, + passwordInput.value + ); + console.log(seed, x); + u.$http.post('@auth_ajax/challenge{?public,seed}', {}, { + vars: { + seed, + public: x + } + }); +}); diff --git a/src/Module/Front/Auth/views/login.blade.php b/src/Module/Front/Auth/views/login.blade.php index 76f804f6..a8f44dd0 100644 --- a/src/Module/Front/Auth/views/login.blade.php +++ b/src/Module/Front/Auth/views/login.blade.php @@ -16,6 +16,7 @@ * @var $lang LangService The language translation service. */ +use Unicorn\Script\UnicornScript; use Windwalker\Core\Application\AppContext; use Windwalker\Core\Asset\AssetService; use Windwalker\Core\DateTime\ChronosService; @@ -23,6 +24,9 @@ use Windwalker\Core\Router\Navigator; use Windwalker\Core\Router\SystemUri; +$uniScript = $app->service(UnicornScript::class); +$uniScript->addRoute('@auth_ajax'); + ?> @extends($app->config('luna.view_extends.front.auth') ?? 'global.auth') @@ -78,15 +82,15 @@
-{{--
--}} -{{--
--}} -{{-- --}} -{{-- --}} -{{--
--}} -{{--
--}} + {{--
--}} + {{--
--}} + {{-- --}} + {{-- --}} + {{--
--}} + {{--
--}}