Skip to content

Commit 4586040

Browse files
committed
OXDEV-9078 Add User DTO with temporary NewUser name, also a repository to get it
1 parent 621b6a4 commit 4586040

18 files changed

Lines changed: 336 additions & 56 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO;
11+
12+
class NewUser implements NewUserInterface
13+
{
14+
public function __construct(
15+
private string $userId,
16+
private string $email,
17+
) {
18+
}
19+
20+
public function getUserId(): string
21+
{
22+
return $this->userId;
23+
}
24+
25+
public function getEmail(): string
26+
{
27+
return $this->email;
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO;
11+
12+
interface NewUserInterface
13+
{
14+
public function getUserId(): string;
15+
16+
public function getEmail(): string;
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory;
11+
12+
use OxidEsales\Eshop\Application\Model\User;
13+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\NewUser;
14+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\NewUserInterface;
15+
16+
class NewUserFactory implements NewUserFactoryInterface
17+
{
18+
public function createFromModel(User $userModel): NewUserInterface
19+
{
20+
return new NewUser(
21+
userId: $userModel->getId(),
22+
email: $userModel->getFieldData('oxusername'),
23+
);
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory;
11+
12+
use OxidEsales\Eshop\Application\Model\User;
13+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\NewUserInterface;
14+
15+
interface NewUserFactoryInterface
16+
{
17+
public function createFromModel(User $userModel): NewUserInterface;
18+
}

src/Authentication/TwoFactorAuth/Infrastructure/Factory/UserFactory.php renamed to src/Authentication/TwoFactorAuth/Infrastructure/Factory/UserModelFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use OxidEsales\Eshop\Application\Model\User;
1313

14-
class UserFactory implements UserFactoryInterface
14+
class UserModelFactory implements UserModelFactoryInterface
1515
{
1616
/**
1717
* @inheritDoc

src/Authentication/TwoFactorAuth/Infrastructure/Factory/UserFactoryInterface.php renamed to src/Authentication/TwoFactorAuth/Infrastructure/Factory/UserModelFactoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use OxidEsales\Eshop\Application\Model\User;
1111

12-
interface UserFactoryInterface
12+
interface UserModelFactoryInterface
1313
{
1414
public function create(): User;
1515
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository;
11+
12+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\NewUserInterface;
13+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\UserNotFoundException;
14+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory\NewUserFactoryInterface;
15+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory\UserModelFactoryInterface;
16+
17+
class NewUserRepository implements NewUserRepositoryInterface
18+
{
19+
public function __construct(
20+
private UserModelFactoryInterface $userFactory,
21+
private NewUserFactoryInterface $userDtoFactory,
22+
) {
23+
}
24+
25+
public function getUserById(string $userId): NewUserInterface
26+
{
27+
$userModel = $this->userFactory->create();
28+
29+
if (!$userModel->load($userId)) {
30+
throw new UserNotFoundException();
31+
}
32+
33+
return $this->userDtoFactory->createFromModel($userModel);
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository;
11+
12+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\NewUserInterface;
13+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\UserNotFoundException;
14+
15+
interface NewUserRepositoryInterface
16+
{
17+
/** @throws UserNotFoundException */
18+
public function getUserById(string $userId): NewUserInterface;
19+
}

src/Authentication/TwoFactorAuth/Infrastructure/Repository/UserRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\UserInterface;
1818
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\DTO\User as UserDTO;
1919
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\UserNotFoundException;
20-
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory\UserFactoryInterface;
20+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Factory\UserModelFactoryInterface;
2121

2222
class UserRepository implements UserRepositoryInterface
2323
{
2424
public function __construct(
25-
private readonly UserFactoryInterface $userFactory,
25+
private readonly UserModelFactoryInterface $userFactory,
2626
private readonly QueryBuilderFactoryInterface $queryBuilderFactory,
2727
private readonly ContextInterface $context,
2828
) {

src/Authentication/TwoFactorAuth/Infrastructure/Repository/services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ services:
33
autowire: true
44
public: false
55

6+
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\NewUserRepositoryInterface:
7+
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\NewUserRepository
8+
69
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\UserRepositoryInterface:
710
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\UserRepository
811
public: true

0 commit comments

Comments
 (0)