From 0ea58dc38ab19795e0c251f944ff09fb6d67fec9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 May 2022 10:14:41 +0900 Subject: [PATCH] fix: add null check for email address --- src/Authentication/Actions/EmailActivator.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Authentication/Actions/EmailActivator.php b/src/Authentication/Actions/EmailActivator.php index 3f9cd0a0e..4eb4d8ae0 100644 --- a/src/Authentication/Actions/EmailActivator.php +++ b/src/Authentication/Actions/EmailActivator.php @@ -5,6 +5,7 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RedirectResponse; +use CodeIgniter\Shield\Exceptions\LogicException; use CodeIgniter\Shield\Exceptions\RuntimeException; use CodeIgniter\Shield\Models\UserIdentityModel; @@ -23,6 +24,13 @@ public function show(): string throw new RuntimeException('Cannot get the User.'); } + $userEmail = $user->getAuthEmail(); + if ($userEmail === null) { + throw new LogicException( + 'Email Activation needs user email address. user_id: ' . $user->getAuthId() + ); + } + /** @var UserIdentityModel $identityModel */ $identityModel = model(UserIdentityModel::class); @@ -44,7 +52,7 @@ public function show(): string // Send the email helper('email'); $return = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '') - ->setTo($user->getAuthEmail()) + ->setTo($userEmail) ->setSubject(lang('Auth.emailActivateSubject')) ->setMessage(view(setting('Auth.views')['action_email_activate_email'], ['code' => $code])) ->send();