diff --git a/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php b/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php index 146729b122..4466f7a026 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Email/EmailLogin.php @@ -43,6 +43,8 @@ use Espo\Core\Authentication\Result\FailReason; use Espo\Core\Api\Request; +use RuntimeException; + class EmailLogin implements Login { /** @@ -62,13 +64,23 @@ class EmailLogin implements Login { $code = $request->getHeader('Espo-Authorization-Code'); - if (!$code) { - $this->util->sendCode($result->getLoggedUser()); + $loggedUser = $result->getLoggedUser(); - return Result::secondStepRequired($result->getUser(), $this->getResultData()); + if (!$loggedUser) { + throw new RuntimeException("No logged-user."); } - $loggedUser = $result->getLoggedUser(); + if (!$code) { + $user = $result->getUser(); + + if (!$user) { + throw new RuntimeException("No user."); + } + + $this->util->sendCode($loggedUser); + + return Result::secondStepRequired($user, $this->getResultData()); + } if ($this->verifyCode($loggedUser, $code)) { return $result; diff --git a/application/Espo/Core/Authentication/TwoFactor/Email/Util.php b/application/Espo/Core/Authentication/TwoFactor/Email/Util.php index 754905bd71..8bd2ebab54 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Email/Util.php +++ b/application/Espo/Core/Authentication/TwoFactor/Email/Util.php @@ -115,6 +115,10 @@ class Util $userData = $this->getUserDataRepository()->getByUserId($user->getId()); + if (!$userData) { + throw new Error("UserData not found."); + } + $userData->set('auth2FAEmailAddress', $emailAddress); $this->entityManager->saveEntity($userData); @@ -215,7 +219,8 @@ class Util throw new Error("User does not have email address."); } - return $user->getEmailAddressGroup()->getPrimary()->getAddress(); + /** @var string */ + return $user->getEmailAddressGroup()->getPrimaryAddress(); } private function checkEmailAddressIsUsers(User $user, string $emailAddress): void diff --git a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php index 0a35181f34..dbc9bb3a36 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsLogin.php @@ -42,6 +42,8 @@ use Espo\Core\Authentication\Result\Data as ResultData; use Espo\Core\Authentication\Result\FailReason; use Espo\Core\Api\Request; +use RuntimeException; + class SmsLogin implements Login { /** @@ -61,13 +63,23 @@ class SmsLogin implements Login { $code = $request->getHeader('Espo-Authorization-Code'); - if (!$code) { - $this->util->sendCode($result->getLoggedUser()); + $loggedUser = $result->getLoggedUser(); - return Result::secondStepRequired($result->getUser(), $this->getResultData()); + if (!$loggedUser) { + throw new RuntimeException("No logged-user."); } - $loggedUser = $result->getLoggedUser(); + if (!$code) { + $user = $result->getUser(); + + if (!$user) { + throw new RuntimeException("No user."); + } + + $this->util->sendCode($loggedUser); + + return Result::secondStepRequired($user, $this->getResultData()); + } if ($this->verifyCode($loggedUser, $code)) { return $result; diff --git a/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php b/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php index fab43832ea..b46e051ffb 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php +++ b/application/Espo/Core/Authentication/TwoFactor/Sms/Util.php @@ -110,6 +110,10 @@ class Util $userData = $this->getUserDataRepository()->getByUserId($user->getId()); + if (!$userData) { + throw new Error(); + } + $userData->set('auth2FASmsPhoneNumber', $phoneNumber); $this->entityManager->saveEntity($userData); @@ -210,7 +214,8 @@ class Util throw new Error("User does not have phone number."); } - return $user->getPhoneNumberGroup()->getPrimary()->getNumber(); + /** @var string */ + return $user->getPhoneNumberGroup()->getPrimaryNumber(); } private function checkPhoneNumberIsUsers(User $user, string $phoneNumber): void diff --git a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php index 61148844e9..961039add0 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php +++ b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpLogin.php @@ -43,6 +43,8 @@ use Espo\Core\Authentication\Result\FailReason; use Espo\Core\Api\Request; +use RuntimeException; + class TotpLogin implements Login { /** @@ -63,11 +65,21 @@ class TotpLogin implements Login $code = $request->getHeader('Espo-Authorization-Code'); if (!$code) { - return Result::secondStepRequired($result->getUser(), $this->getResultData()); + $user = $result->getUser(); + + if (!$user) { + throw new RuntimeException("No user."); + } + + return Result::secondStepRequired($user, $this->getResultData()); } $loggedUser = $result->getLoggedUser(); + if (!$loggedUser) { + throw new RuntimeException("No logged-user."); + } + if ($this->verifyCode($loggedUser, $code)) { return $result; } diff --git a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php index 19fa444feb..3ba7b3aad2 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php +++ b/application/Espo/Core/Authentication/TwoFactor/Totp/TotpUserSetup.php @@ -103,6 +103,10 @@ class TotpUserSetup implements UserSetup { $userData = $this->getUserDataRepository()->getByUserId($user->getId()); + if (!$userData) { + throw new Error(); + } + $userData->set('auth2FATotpSecret', $secret); $this->entityManager->saveEntity($userData); diff --git a/application/Espo/Core/Binding/BindingContainer.php b/application/Espo/Core/Binding/BindingContainer.php index dbc76739b4..0c11e224f9 100644 --- a/application/Espo/Core/Binding/BindingContainer.php +++ b/application/Espo/Core/Binding/BindingContainer.php @@ -64,6 +64,7 @@ class BindingContainer throw new LogicException("BindingContainer: Can't get not existing binding."); } + /** @var Binding */ return $this->getInternal($class, $param); } @@ -82,7 +83,7 @@ class BindingContainer $key = '$' . $param->getName(); } - if ($className && $this->data->hasContext($className, $key) && $key) { + if ($className && $key && $this->data->hasContext($className, $key)) { return $this->data->getContext($className, $key); } diff --git a/application/Espo/Core/Console/CommandManager.php b/application/Espo/Core/Console/CommandManager.php index 728e910019..252334b8fb 100644 --- a/application/Espo/Core/Console/CommandManager.php +++ b/application/Espo/Core/Console/CommandManager.php @@ -139,7 +139,7 @@ class CommandManager throw new CommandNotFound("Command '" . Util::camelCaseToHyphen($command) ."' does not exist."); } - /** @var ?class-string */ + /** @var class-string */ return $className; } diff --git a/application/Espo/Core/Console/Commands/AclCheck.php b/application/Espo/Core/Console/Commands/AclCheck.php index d62dafff8a..16639269fc 100644 --- a/application/Espo/Core/Console/Commands/AclCheck.php +++ b/application/Espo/Core/Console/Commands/AclCheck.php @@ -83,6 +83,7 @@ class AclCheck implements Command } if ($user->isPortal()) { + /** @var string[] */ $portalIdList = $user->getLinkMultipleIdList('portals'); foreach ($portalIdList as $portalId) {