add initial admin
This commit is contained in:
parent
b55769516e
commit
0d2c44da13
2 changed files with 43 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\User\UseCases\EnsureInitialAdmin;
|
||||
|
||||
use App\Auth\PasswordHasher;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use App\User\CreateUserDto;
|
||||
use App\User\UserRepository;
|
||||
|
||||
class EnsureInitialAdmin
|
||||
{
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private PasswordHasher $passwordHasher,
|
||||
) {
|
||||
}
|
||||
|
||||
public function execute(EnsureInitialAdminRequest $request): void
|
||||
{
|
||||
$email = new EmailAddress($request->email);
|
||||
$existingUser = $this->userRepository->findByEmail($email);
|
||||
if ($existingUser !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->userRepository->create(new CreateUserDto(
|
||||
email: $email,
|
||||
passwordHash: $this->passwordHasher->hash($request->password),
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue