From c84b7ab16a5f1b9d23a87dfefd0398a0b07174ab Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:58:15 -0300 Subject: [PATCH] Allow disable register accounts. (#18) --- src/UseCase/Register/RegisterController.php | 6 ++++++ src/UseCase/Register/RegisterEvent.php | 1 + src/UseCase/Register/view/index.php | 7 +++---- tests/Acceptance/RegisterCest.php | 15 +++++++++++++++ tests/Support/AcceptanceTester.php | 12 ++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/UseCase/Register/RegisterController.php b/src/UseCase/Register/RegisterController.php index 3c4d97e..23b6a92 100644 --- a/src/UseCase/Register/RegisterController.php +++ b/src/UseCase/Register/RegisterController.php @@ -59,6 +59,12 @@ public function actionIndex(): Response|string $registerForm = new $this->formModelClass($this->userModule); $event = new RegisterEvent($registerForm, $this->userModule); + if ($this->userModule->register === false) { + $this->trigger(RegisterEvent::MODULE_DISABLE, $event); + + return $this->goHome(); + } + $this->trigger(RegisterEvent::BEFORE_REGISTER, $event); $this->ajaxValidator->validate($registerForm); diff --git a/src/UseCase/Register/RegisterEvent.php b/src/UseCase/Register/RegisterEvent.php index 7b09ea4..fa801b8 100644 --- a/src/UseCase/Register/RegisterEvent.php +++ b/src/UseCase/Register/RegisterEvent.php @@ -12,6 +12,7 @@ final class RegisterEvent extends Event { public const AFTER_REGISTER = 'afterRegister'; public const BEFORE_REGISTER = 'beforeRegister'; + public const MODULE_DISABLE = 'moduleDisable'; public function __construct( public readonly Model $formModel, diff --git a/src/UseCase/Register/view/index.php b/src/UseCase/Register/view/index.php index e3b3b7f..f92e75a 100644 --- a/src/UseCase/Register/view/index.php +++ b/src/UseCase/Register/view/index.php @@ -132,13 +132,12 @@ ), A::widget() ->ariaLabel('github-button') - ->class('btn btn-icon-only btn-pill btn-outline-gray-500') + ->class('mb-2') ->content( Span::widget() - ->class('fa-stack fa-2x') + ->class('btn btn-outline-secondary fa-2x') ->content( - Icon::renderIcon('solid', 'square-full', ['class' => 'fas fa-stack-2x']), - Icon::renderIcon('brands', 'github', ['class' => 'fab fa-stack-1x fa-inverse text-center']) + Icon::renderIcon('brands', 'github', ['class' => 'text-center']) ) ) ->href('#') diff --git a/tests/Acceptance/RegisterCest.php b/tests/Acceptance/RegisterCest.php index a855f03..f341f65 100644 --- a/tests/Acceptance/RegisterCest.php +++ b/tests/Acceptance/RegisterCest.php @@ -9,6 +9,21 @@ final class RegisterCest { + public function disablePage(AcceptanceTester $I): void + { + $I->amGoingTo('disable register page.'); + $I->accountRegister(false); + + $I->amGoingTo('go to the page registration.'); + $I->amOnRoute('register/index'); + + $I->expectTo('see message register disabled.'); + $I->see(Yii::t('app.basic', 'Web Application')); + + $I->amGoingTo('enable register page.'); + $I->accountRegister(true); + } + public function indexPage(AcceptanceTester $I): void { $I->amGoingTo('navigate to the register page.'); diff --git a/tests/Support/AcceptanceTester.php b/tests/Support/AcceptanceTester.php index 7799f3d..575a90b 100644 --- a/tests/Support/AcceptanceTester.php +++ b/tests/Support/AcceptanceTester.php @@ -50,4 +50,16 @@ public function accountGeneratePassword(bool $option): void ], ); } + + public function accountRegister(bool $option): void + { + \Yii::$container->set( + \Yii\User\UserModule::class, + [ + '__construct()' => [ + 'register' => $option, + ], + ], + ); + } }