From 332911aec96afd2e2df338993db0c7221c3e9053 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 18 Oct 2023 11:23:01 -0300 Subject: [PATCH] Add accept_terms. --- src/UseCase/Register/RegisterForm.php | 8 ++++++++ src/UseCase/Register/view/index.php | 19 +++++++++++++++---- tests/Acceptance/RegisterCest.php | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/UseCase/Register/RegisterForm.php b/src/UseCase/Register/RegisterForm.php index 87bd223..1ace670 100644 --- a/src/UseCase/Register/RegisterForm.php +++ b/src/UseCase/Register/RegisterForm.php @@ -11,6 +11,7 @@ final class RegisterForm extends Model { + public bool $accept_terms = false; public int|null $confirmed_at = null; public int|null $created_at = null; public string $email = ''; @@ -38,6 +39,13 @@ public function attributeLabels(): array public function rules(): array { return [ + // acceptTerms rules + 'acceptTermsRequired' => [ + 'accept_terms', + 'compare', + 'compareValue' => true, + 'message' => Yii::t('yii.user', 'You must accept the terms and conditions.'), + ], // create_at only first register 'createdAtDefault' => ['created_at', 'default', 'value' => time()], // confirmed_at only if $this->userModule->confirmation === false diff --git a/src/UseCase/Register/view/index.php b/src/UseCase/Register/view/index.php index 42d5a1c..b678eb4 100644 --- a/src/UseCase/Register/view/index.php +++ b/src/UseCase/Register/view/index.php @@ -56,7 +56,7 @@ [ 'autofocus' => true, 'oninput' => 'this.setCustomValidity("")', - 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Email Here') . '")', + 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Email Here.') . '")', 'placeholder' => Yii::t('yii.user', 'Email'), 'required' => (YII_ENV === 'test') ? false : true, 'tabindex' => '1', @@ -67,7 +67,7 @@ ->textInput( [ 'oninput' => 'this.setCustomValidity("")', - 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Username Here') . '")', + 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Username Here.') . '")', 'placeholder' => Yii::t('yii.user', 'Username'), 'required' => (YII_ENV === 'test') ? false : true, 'tabindex' => '2', @@ -79,7 +79,7 @@ ->passwordInput( [ 'oninput' => 'this.setCustomValidity("")', - 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Password Here') . '")', + 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Password Here.') . '")', 'placeholder' => Yii::t('yii.user', 'Password'), 'required' => (YII_ENV === 'test') ? false : true, 'tabindex' => '3', @@ -90,7 +90,7 @@ ->passwordInput( [ 'oninput' => 'this.setCustomValidity("")', - 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Password Here') . '")', + 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'Enter Password Here.') . '")', 'placeholder' => Yii::t('yii.user', 'Password'), 'required' => (YII_ENV === 'test') ? false : true, 'tabindex' => '4', @@ -98,6 +98,17 @@ ) ?> + field($registerForm, 'accept_terms') + ->checkbox( + [ + 'class' => 'form-check-input', + 'oninvalid' => 'this.setCustomValidity("' . Yii::t('yii.user', 'You must accept the terms and conditions.') . '")', + 'required' => (YII_ENV === 'test') ? false : true, + 'tabindex' => '5', + 'template' => "
\n{input}\n{label}\n{error}\n{hint}\n
", + ], + ) + ?> 'd-grid gap-2']) ?> fillField('#registerform-username', 'admin1'); $I->fillField('#registerform-password', '123456'); $I->fillField('#registerform-passwordrepeat', '123456'); + $I->checkOption('#registerform-accept_terms'); $I->click('Sign up'); $I->expectTo('see message error validation.'); @@ -48,6 +49,7 @@ public function successWithConfirmTrue(AcceptanceTester $I): void $I->fillField('#registerform-username', 'admin2'); $I->fillField('#registerform-password', '123456'); $I->fillField('#registerform-passwordrepeat', '123456'); + $I->checkOption('#registerform-accept_terms'); $I->click('Sign up'); $I->expectTo('see message error validation.'); @@ -68,6 +70,7 @@ public function successWithGeneratePasswordTrue(AcceptanceTester $I): void $I->expectTo('see registration form.'); $I->fillField('#registerform-email', 'admin3@example.com'); $I->fillField('#registerform-username', 'admin3'); + $I->checkOption('#registerform-accept_terms'); $I->click('Sign up'); $I->expectTo('see message error validation.');