mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
ref
This commit is contained in:
@@ -29,21 +29,25 @@
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
|
||||
use Espo\Tools\UserSecurity\TwoFactorEmailService as Service;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Tools\UserSecurity\TwoFactor\EmailService as Service;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class TwoFactorEmail
|
||||
{
|
||||
private $service;
|
||||
|
||||
private $user;
|
||||
private Service $service;
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function __construct(Service $service, User $user)
|
||||
{
|
||||
$this->service = $service;
|
||||
@@ -56,6 +60,13 @@ class TwoFactorEmail
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
* @throws NotFound
|
||||
*/
|
||||
public function postActionSendCode(Request $request): bool
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
@@ -29,21 +29,25 @@
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
|
||||
use Espo\Tools\UserSecurity\TwoFactorSmsService as Service;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Tools\UserSecurity\TwoFactor\SmsService as Service;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class TwoFactorSms
|
||||
{
|
||||
private $service;
|
||||
|
||||
private $user;
|
||||
private Service $service;
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function __construct(Service $service, User $user)
|
||||
{
|
||||
$this->service = $service;
|
||||
@@ -56,6 +60,13 @@ class TwoFactorSms
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
* @throws NotFound
|
||||
*/
|
||||
public function postActionSendCode(Request $request): bool
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
@@ -27,8 +27,9 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Tools\UserSecurity;
|
||||
namespace Espo\Tools\UserSecurity\TwoFactor;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
|
||||
@@ -39,7 +40,7 @@ use Espo\ORM\EntityManager;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class TwoFactorEmailService
|
||||
class EmailService
|
||||
{
|
||||
private Util $util;
|
||||
private User $user;
|
||||
@@ -58,6 +59,11 @@ class TwoFactorEmailService
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws NotFound
|
||||
* @throws Error
|
||||
*/
|
||||
public function sendCode(string $userId, string $emailAddress): void
|
||||
{
|
||||
if (!$this->user->isAdmin() && $userId !== $this->user->getId()) {
|
||||
@@ -66,6 +72,7 @@ class TwoFactorEmailService
|
||||
|
||||
$this->checkAllowed();
|
||||
|
||||
/** @var ?User $user */
|
||||
$user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId);
|
||||
|
||||
if (!$user) {
|
||||
@@ -76,6 +83,9 @@ class TwoFactorEmailService
|
||||
$this->util->storeEmailAddress($user, $emailAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
private function checkAllowed(): void
|
||||
{
|
||||
if (!$this->config->get('auth2FA')) {
|
||||
@@ -27,8 +27,9 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Tools\UserSecurity;
|
||||
namespace Espo\Tools\UserSecurity\TwoFactor;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
|
||||
@@ -39,7 +40,7 @@ use Espo\ORM\EntityManager;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class TwoFactorSmsService
|
||||
class SmsService
|
||||
{
|
||||
private Util $util;
|
||||
private User $user;
|
||||
@@ -58,6 +59,11 @@ class TwoFactorSmsService
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws NotFound
|
||||
* @throws Error
|
||||
*/
|
||||
public function sendCode(string $userId, string $phoneNumber): void
|
||||
{
|
||||
if (!$this->user->isAdmin() && $userId !== $this->user->getId()) {
|
||||
@@ -66,6 +72,7 @@ class TwoFactorSmsService
|
||||
|
||||
$this->checkAllowed();
|
||||
|
||||
/** @var ?User $user */
|
||||
$user = $this->entityManager->getEntity(User::ENTITY_TYPE, $userId);
|
||||
|
||||
if (!$user) {
|
||||
@@ -76,6 +83,9 @@ class TwoFactorSmsService
|
||||
$this->util->storePhoneNumber($user, $phoneNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
private function checkAllowed(): void
|
||||
{
|
||||
if (!$this->config->get('auth2FA')) {
|
||||
Reference in New Issue
Block a user