rename
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ use RuntimeException;
|
||||
/**
|
||||
* An auth token data. Used for auth token creation.
|
||||
*/
|
||||
class AuthTokenData
|
||||
class Data
|
||||
{
|
||||
private $userId;
|
||||
|
||||
+14
-15
@@ -29,33 +29,32 @@
|
||||
|
||||
namespace Espo\Core\Authentication\AuthToken;
|
||||
|
||||
use Espo\{
|
||||
ORM\EntityManager,
|
||||
};
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Entities\AuthToken as AuthTokenEntity;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
use const MCRYPT_DEV_URANDOM;
|
||||
|
||||
class EspoAuthTokenManager implements AuthTokenManager
|
||||
class EspoManager implements Manager
|
||||
{
|
||||
protected $entityManager;
|
||||
private $entityManager;
|
||||
|
||||
protected $repository;
|
||||
private $repository;
|
||||
|
||||
const TOKEN_RANDOM_LENGTH = 16;
|
||||
private const TOKEN_RANDOM_LENGTH = 16;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
|
||||
$this->repository = $entityManager->getRepository('AuthToken');
|
||||
$this->repository = $entityManager->getRepository(AuthTokenEntity::ENTITY_TYPE);
|
||||
}
|
||||
|
||||
public function get(string $token): ?AuthToken
|
||||
{
|
||||
$authToken = $this->entityManager
|
||||
->getRepository('AuthToken')
|
||||
->getRDBRepository(AuthTokenEntity::ENTITY_TYPE)
|
||||
->select([
|
||||
'id',
|
||||
'isActive',
|
||||
@@ -76,20 +75,20 @@ class EspoAuthTokenManager implements AuthTokenManager
|
||||
return $authToken;
|
||||
}
|
||||
|
||||
public function create(AuthTokenData $authTokenData): AuthToken
|
||||
public function create(Data $data): AuthToken
|
||||
{
|
||||
$authToken = $this->repository->getNew();
|
||||
|
||||
$authToken->set([
|
||||
'userId' => $authTokenData->getUserId(),
|
||||
'portalId' => $authTokenData->getPortalId(),
|
||||
'hash' => $authTokenData->getHash(),
|
||||
'ipAddress' => $authTokenData->getIpAddress(),
|
||||
'userId' => $data->getUserId(),
|
||||
'portalId' => $data->getPortalId(),
|
||||
'hash' => $data->getHash(),
|
||||
'ipAddress' => $data->getIpAddress(),
|
||||
'lastAccess' => date('Y-m-d H:i:s'),
|
||||
'token' => $this->generateToken(),
|
||||
]);
|
||||
|
||||
if ($authTokenData->toCreateSecret()) {
|
||||
if ($data->toCreateSecret()) {
|
||||
$authToken->set('secret', $this->generateToken());
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ namespace Espo\Core\Authentication\AuthToken;
|
||||
/**
|
||||
* Fetches and stores auth tokens.
|
||||
*/
|
||||
interface AuthTokenManager
|
||||
interface Manager
|
||||
{
|
||||
/**
|
||||
* Get an auth token. If does not exist then returns NULL.
|
||||
@@ -42,7 +42,7 @@ interface AuthTokenManager
|
||||
/**
|
||||
* Create an auth token and store it.
|
||||
*/
|
||||
public function create(AuthTokenData $authTokenData): AuthToken;
|
||||
public function create(Data $data): AuthToken;
|
||||
|
||||
/**
|
||||
* Make an auth token inactive (invalid).
|
||||
@@ -47,8 +47,8 @@ use Espo\Core\Authentication\{
|
||||
Result\FailReason,
|
||||
LoginFactory,
|
||||
TwoFactor\LoginFactory as TwoFactorLoginFactory,
|
||||
AuthToken\AuthTokenManager,
|
||||
AuthToken\AuthTokenData,
|
||||
AuthToken\Manager as AuthTokenManager,
|
||||
AuthToken\Data as AuthTokenData,
|
||||
AuthToken\AuthToken,
|
||||
Hook\Manager as HookManager,
|
||||
Login\Data as LoginData,
|
||||
|
||||
@@ -94,7 +94,7 @@ class DefaultBinding implements BindingProcessor
|
||||
);
|
||||
|
||||
$binder->bindService(
|
||||
'Espo\\Core\\Authentication\\AuthToken\\AuthTokenManager',
|
||||
'Espo\\Core\\Authentication\\AuthToken\\Manager',
|
||||
'authTokenManager'
|
||||
);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\{
|
||||
ORM\EntityManager,
|
||||
Authentication\AuthToken\AuthTokenManager,
|
||||
Authentication\AuthToken\Manager as AuthTokenManager,
|
||||
Console\Command,
|
||||
Console\Command\Params,
|
||||
Console\IO,
|
||||
@@ -39,9 +39,9 @@ use Espo\Core\{
|
||||
|
||||
class AuthTokenCheck implements Command
|
||||
{
|
||||
protected $entityManager;
|
||||
private $entityManager;
|
||||
|
||||
protected $authTokenManager;
|
||||
private $authTokenManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager, AuthTokenManager $authTokenManager)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ use Espo\Core\EntryPoint\EntryPointManager;
|
||||
use Espo\Core\ApplicationUser;
|
||||
use Espo\Core\Portal\Application as PortalApplication;
|
||||
use Espo\Core\Authentication\AuthenticationFactory;
|
||||
use Espo\Core\Authentication\AuthToken\AuthTokenManager;
|
||||
use Espo\Core\Authentication\AuthToken\Manager as AuthTokenManager;
|
||||
use Espo\Core\Api\ErrorOutput;
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
use Espo\Core\Api\ResponseWrapper;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"authTokenManager": {
|
||||
"className": "Espo\\Core\\Authentication\\AuthToken\\EspoAuthTokenManager"
|
||||
"className": "Espo\\Core\\Authentication\\AuthToken\\EspoManager"
|
||||
},
|
||||
"schema": {
|
||||
"className": "Espo\\Core\\Utils\\Database\\Schema\\Schema"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace tests\integration\Espo\Core\Authentication\AuthToken;
|
||||
|
||||
use Espo\Core\Authentication\AuthToken\AuthTokenData;
|
||||
use Espo\Core\Authentication\AuthToken\Data;
|
||||
|
||||
class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
@@ -37,7 +37,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->get('authTokenManager');
|
||||
|
||||
$authTokenData = AuthTokenData::create([
|
||||
$authTokenData = Data::create([
|
||||
'hash' => 'test-hash',
|
||||
'ipAddress' => 'ip-address',
|
||||
'userId' => 'user-id',
|
||||
@@ -63,7 +63,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->get('authTokenManager');
|
||||
|
||||
$authTokenData = AuthTokenData::create([
|
||||
$authTokenData = Data::create([
|
||||
'hash' => 'test-hash',
|
||||
'ipAddress' => 'ip-address',
|
||||
'userId' => 'user-id',
|
||||
@@ -86,7 +86,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->get('authTokenManager');
|
||||
|
||||
$authTokenData = AuthTokenData::create([
|
||||
$authTokenData = Data::create([
|
||||
'hash' => 'test-hash',
|
||||
'userId' => 'user-id',
|
||||
]);
|
||||
@@ -104,7 +104,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->get('authTokenManager');
|
||||
|
||||
$authTokenData = AuthTokenData::create([
|
||||
$authTokenData = Data::create([
|
||||
'hash' => 'test-hash',
|
||||
'userId' => 'user-id',
|
||||
]);
|
||||
|
||||
@@ -29,13 +29,13 @@
|
||||
|
||||
namespace tests\unit\Espo\Core\Authentication\AuthToken;
|
||||
|
||||
use Espo\Core\Authentication\AuthToken\AuthTokenData;
|
||||
use Espo\Core\Authentication\AuthToken\Data;
|
||||
|
||||
class AuthTokenDataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$authTokenData = AuthTokenData::create([
|
||||
$authTokenData = Data::create([
|
||||
'hash' => 'hash',
|
||||
'ipAddress' => 'ip-address',
|
||||
'userId' => 'user-id',
|
||||
|
||||
Reference in New Issue
Block a user