From e66cdf96109bd7a27f9ee2e6653db16d8eee68ff Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 18 Nov 2023 11:09:18 +0200 Subject: [PATCH] 2fa error impr --- .../Authentication/TwoFactor/Sms/SmsUserSetup.php | 2 +- application/Espo/Resources/i18n/en_US/User.json | 1 + application/Espo/Tools/UserSecurity/Service.php | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsUserSetup.php b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsUserSetup.php index 2e8b6f257b..e72248e80c 100644 --- a/application/Espo/Core/Authentication/TwoFactor/Sms/SmsUserSetup.php +++ b/application/Espo/Core/Authentication/TwoFactor/Sms/SmsUserSetup.php @@ -50,7 +50,7 @@ class SmsUserSetup implements UserSetup public function getData(User $user): stdClass { if (!$this->config->get('smsProvider')) { - throw new NotConfigured("No SMS provider. Need to configure an SMS provider."); + throw new NotConfigured("No SMS provider."); } return (object) [ diff --git a/application/Espo/Resources/i18n/en_US/User.json b/application/Espo/Resources/i18n/en_US/User.json index e8a2e0806d..90401578e9 100644 --- a/application/Espo/Resources/i18n/en_US/User.json +++ b/application/Espo/Resources/i18n/en_US/User.json @@ -99,6 +99,7 @@ "layoutSet": "Layouts from a specified set will be applied for the user instead of default ones." }, "messages": { + "2faMethodNotConfigured": "The 2FA method is not fully configured in the system.", "loginAs": "Open the login link in an incognito window to preserve your current session. Use your admin credentials to log in.", "sendPasswordChangeLinkConfirmation": "An email with a unique link will be sent to the user allowing them to change their password. The link will expire after a specific amount of time.", "passwordRecoverySentIfMatched": "Assuming the entered data matched any user account.", diff --git a/application/Espo/Tools/UserSecurity/Service.php b/application/Espo/Tools/UserSecurity/Service.php index 6e93501bc7..740153b868 100644 --- a/application/Espo/Tools/UserSecurity/Service.php +++ b/application/Espo/Tools/UserSecurity/Service.php @@ -30,9 +30,12 @@ namespace Espo\Tools\UserSecurity; use Espo\Core\Authentication\TwoFactor\Exceptions\NotConfigured; +use Espo\Core\Exceptions\Error\Body; use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Exceptions\ForbiddenSilent; use Espo\Core\Exceptions\NotFound; use Espo\Core\Exceptions\BadRequest; +use Espo\Core\Utils\Log; use Espo\ORM\EntityManager; use Espo\Entities\User; use Espo\Entities\UserData; @@ -52,7 +55,8 @@ class Service private User $user, private Config $config, private LoginFactory $authLoginFactory, - private TwoFactorUserSetupFactory $twoFactorUserSetupFactory + private TwoFactorUserSetupFactory $twoFactorUserSetupFactory, + private Log $log ) {} /** @@ -154,7 +158,12 @@ class Service ->getData($user); } catch (NotConfigured $e) { - throw new Forbidden($e->getMessage()); + $this->log->error($e->getMessage()); + + throw Forbidden::createWithBody( + "2FA method '$auth2FAMethod' is not fully configured.", + Body::create()->withMessageTranslation('2faMethodNotConfigured', 'User') + ); } if ($isReset) {