Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak: Added a check if the user already exists for the "oe:admin:c… #944

Open
wants to merge 2 commits into
base: b-7.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions source/Internal/Domain/Admin/Dao/AdminDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ public function create(Admin $admin): void
]);
$queryBuilder->execute();
}

# check if username for email and shop id exists
public function userNameExists(string $email, int $shopId): bool {
$queryBuilder = $this->queryBuilderFactory->create();
$queryBuilder
->select('OXID')
->from('oxuser')
->where('OXUSERNAME = :OXUSERNAME')
->andWhere('OXSHOPID = :OXSHOPID')
->setParameters([
'OXUSERNAME' => $email,
'OXSHOPID' => $shopId,
]);
$result = $queryBuilder->execute()->fetchOne();
return $result !== false;
}
}
2 changes: 2 additions & 0 deletions source/Internal/Domain/Admin/Dao/AdminDaoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface AdminDaoInterface
* @param Admin $admin
*/
public function create(Admin $admin): void;

public function userNameExists(string $email, int $shopId): bool;
}
10 changes: 9 additions & 1 deletion source/Internal/Domain/Admin/Factory/AdminFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
use OxidEsales\EshopCommunity\Internal\Domain\Admin\Exception\InvalidEmailException;
use OxidEsales\EshopCommunity\Internal\Domain\Admin\Exception\InvalidRightsException;
use OxidEsales\EshopCommunity\Internal\Domain\Admin\Exception\InvalidShopException;
use OxidEsales\EshopCommunity\Internal\Domain\Admin\Exception\UserExistsException;
use OxidEsales\EshopCommunity\Internal\Utility\Email\EmailValidatorServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\EshopCommunity\Internal\Utility\Hash\Service\PasswordHashServiceInterface;
use OxidEsales\EshopCommunity\Internal\Domain\Admin\Dao\AdminDaoInterface;

class AdminFactory implements AdminFactoryInterface
{
public function __construct(
private ShopAdapterInterface $shopAdapter,
private EmailValidatorServiceInterface $emailValidatorService,
private PasswordHashServiceInterface $passwordHashService
private PasswordHashServiceInterface $passwordHashService,
private AdminDaoInterface $adminDaoService
) {
}

Expand Down Expand Up @@ -51,6 +54,11 @@ public function createAdmin(
if (!$this->shopAdapter->validateShopId($shopId)) {
throw new InvalidShopException($shopId);
}

if($this->adminDaoService->userNameExists($email, $shopId)) {
echo 'User already exists: '.$email.PHP_EOL;
exit;
}

return new Admin(
$this->shopAdapter->generateUniqueId(),
Expand Down