Skip to content

Commit

Permalink
Add accept_terms.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Oct 18, 2023
1 parent 3307d3c commit 332911a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/UseCase/Register/RegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/UseCase/Register/view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -90,14 +90,25 @@
->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',
]
)
?>
<?php endif ?>
<?= $form->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' => "<div class=\"form-check form-switch\">\n{input}\n{label}\n{error}\n{hint}\n</div>",
],
)
?>
<?= Html::beginTag('div', ['class' => 'd-grid gap-2']) ?>
<?= Html::submitButton(
Yii::t('yii.user', 'Sign up'),
Expand Down
3 changes: 3 additions & 0 deletions tests/Acceptance/RegisterCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function success(AcceptanceTester $I): void
$I->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.');
Expand All @@ -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.');
Expand All @@ -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.');
Expand Down

0 comments on commit 332911a

Please sign in to comment.