Skip to content

Commit

Permalink
Add afterPhoneVerified event
Browse files Browse the repository at this point in the history
  • Loading branch information
ajibarra committed Feb 25, 2022
1 parent ef3a33e commit 4a02570
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Model/Table/OtpCodesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CakeDC\Users\Mailer\SMSMailer;
use CakeDC\Users\Mailer\UsersMailer;
use CakeDC\Users\Model\Entity\OtpCode;
use CakeDC\Users\Plugin;

/**
* OtpCodes Model
Expand Down Expand Up @@ -191,9 +192,11 @@ public function validateCode2f($userId, $code): bool
$this->save($otpCode);
throw new \InvalidArgumentException(__d('cake_d_c/users', 'Verification code is not valid. Please try again or request a new one.'));
}
if (!$user->phone_verified) {
if (Configure::read('Code2f.type') === Code2fAuthenticationCheckerInterface::CODE2F_TYPE_PHONE && !$user->phone_verified) {
$user->phone_verified = new FrozenTime();
$this->Users->save($user);
if ($this->Users->save($user)) {
$this->dispatchEvent(Plugin::EVENT_AFTER_PHONE_VERIFIED, ['user' => $user]);
}
}

$otpCode->validated = new FrozenTime();
Expand Down
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Plugin extends BasePlugin
public const EVENT_ON_EXPIRED_TOKEN = 'Users.Global.onExpiredToken';
public const EVENT_AFTER_RESEND_TOKEN_VALIDATION = 'Users.Global.afterResendTokenValidation';
public const EVENT_AFTER_EMAIL_TOKEN_VALIDATION = 'Users.Global.afterEmailTokenValidation';
public const EVENT_AFTER_PHONE_VERIFIED = 'Users.Global.afterPhoneVerified';

/**
* @inheritDoc
Expand Down

0 comments on commit 4a02570

Please sign in to comment.