first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace KupShop\TwoFactorBundle\Security;
use KupShop\UserBundle\Security\User;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
class TwoFactorUser extends User implements TwoFactorInterface
{
private ?string $authCode;
public function isEmailAuthEnabled(): bool
{
$settings = \Settings::getDefault();
$ignoredGroups = $settings['two_factor']['ignored_groups'] ?? [];
foreach ($ignoredGroups as $ignoredGroup) {
if ($this->getKupshopUser()->hasGroupId($ignoredGroup)) {
return false;
}
}
return findModule(\Modules::TWO_FACTOR) && ($settings['two_factor']['enabled'] ?? false);
}
public function getEmailAuthRecipient(): string
{
return $this->email;
}
public function getEmailAuthCode(): string
{
$code = $this->authCode ?? null;
if (!$code) {
$code = $this->getKupshopUser()->getCustomData()['email_code'];
if (!$code) {
throw new \LogicException('The email authentication code was not set');
}
}
return $code;
}
public function setEmailAuthCode(string $authCode): void
{
$this->authCode = $authCode;
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace KupShop\TwoFactorBundle\Security;
use KupShop\UserBundle\Security\User;
use KupShop\UserBundle\Security\UserProvider;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
class TwoFactorUserProvider extends UserProvider
{
public function loadUserByUsername($username)
{
if (!$email = $this->getEmailByUsername($username)) {
throw new UserNotFoundException();
}
$user = \User::createFromLogin($email);
if (!isset($user)) {
throw new UserNotFoundException();
}
return new TwoFactorUser($user->id, $user->email, $user->passw, ['ROLE_USER'], $user);
}
public function supportsClass($class): bool
{
return $class === TwoFactorUser::class || $class === User::class;
}
}