Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -16,33 +16,18 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
final class LoginManager
{
private $tokenStorage;
private $userChecker;
private $sessionStrategy;
private $requestStack;
private $eventDispatcher;
private $rememberMeService;
public function __construct(
TokenStorageInterface $tokenStorage,
UserChecker $userChecker,
SessionAuthenticationStrategyInterface $sessionStrategy,
RequestStack $requestStack,
EventDispatcherInterface $eventDispatcher,
RememberMeServicesInterface $rememberMeService = null
private TokenStorageInterface $tokenStorage,
private UserChecker $userChecker,
private SessionAuthenticationStrategyInterface $sessionStrategy,
private RequestStack $requestStack,
private EventDispatcherInterface $eventDispatcher,
) {
$this->tokenStorage = $tokenStorage;
$this->userChecker = $userChecker;
$this->sessionStrategy = $sessionStrategy;
$this->requestStack = $requestStack;
$this->eventDispatcher = $eventDispatcher;
$this->rememberMeService = $rememberMeService;
}
public function logInUser(User $user, Response $response = null)
@@ -54,10 +39,6 @@ final class LoginManager
if (null !== $request) {
$this->sessionStrategy->onAuthentication($request, $token);
if (null !== $response && null !== $this->rememberMeService) {
$this->rememberMeService->loginSuccess($request, $response, $token);
}
}
$this->tokenStorage->setToken($token);
@@ -67,6 +48,6 @@ final class LoginManager
private function createToken(string $firewall, User $user): UsernamePasswordToken
{
return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
return new UsernamePasswordToken($user, $firewall, $user->getRoles());
}
}

View File

@@ -11,20 +11,15 @@ namespace App\User;
use App\Repository\TeamRepository;
/**
* @final
*/
class TeamService
final class TeamService
{
/**
* @var array<string, int>
*/
private $cache = [];
private $repository;
private array $cache = [];
public function __construct(TeamRepository $repository)
public function __construct(private TeamRepository $repository)
{
$this->repository = $repository;
}
public function countTeams(): int

View File

@@ -15,13 +15,15 @@ use App\Entity\UserPreference;
use App\Event\UserCreateEvent;
use App\Event\UserCreatePostEvent;
use App\Event\UserCreatePreEvent;
use App\Event\UserDeletePostEvent;
use App\Event\UserDeletePreEvent;
use App\Event\UserUpdatePostEvent;
use App\Event\UserUpdatePreEvent;
use App\Repository\UserRepository;
use App\Validator\ValidationFailedException;
use InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
@@ -32,21 +34,15 @@ class UserService
/**
* @var array<string, int>
*/
private $cache = [];
private array $cache = [];
private $repository;
private $dispatcher;
private $validator;
private $configuration;
private $encoderFactory;
public function __construct(UserRepository $repository, EventDispatcherInterface $dispatcher, ValidatorInterface $validator, SystemConfiguration $configuration, UserPasswordEncoderInterface $encoderFactory)
{
$this->repository = $repository;
$this->dispatcher = $dispatcher;
$this->validator = $validator;
$this->configuration = $configuration;
$this->encoderFactory = $encoderFactory;
public function __construct(
private UserRepository $repository,
private EventDispatcherInterface $dispatcher,
private ValidatorInterface $validator,
private SystemConfiguration $configuration,
private UserPasswordHasherInterface $passwordHasher
) {
}
public function countUser(?bool $enabled = null): int
@@ -133,7 +129,7 @@ class UserService
public function findUserByUsernameOrEmail(string $usernameOrEmail): ?User
{
return $this->repository->loadUserByUsername($usernameOrEmail);
return $this->repository->loadUserByIdentifier($usernameOrEmail);
}
public function findUserByEmail(string $email): ?User
@@ -156,7 +152,7 @@ class UserService
return rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=');
}
private function hashPassword(User $user)
private function hashPassword(User $user): void
{
$plain = $user->getPlainPassword();
@@ -164,12 +160,12 @@ class UserService
return;
}
$password = $this->encoderFactory->encodePassword($user, $plain);
$password = $this->passwordHasher->hashPassword($user, $plain);
$user->setPassword($password);
$user->eraseCredentials();
}
private function hashApiToken(User $user)
private function hashApiToken(User $user): void
{
$plain = $user->getPlainApiToken();
@@ -177,8 +173,15 @@ class UserService
return;
}
$password = $this->encoderFactory->encodePassword($user, $plain);
$password = $this->passwordHasher->hashPassword($user, $plain);
$user->setApiToken($password);
$user->eraseCredentials();
}
public function deleteUser(User $delete, ?User $replace = null): void
{
$this->dispatcher->dispatch(new UserDeletePreEvent($delete, $replace));
$this->repository->deleteUser($delete, $replace);
$this->dispatcher->dispatch(new UserDeletePostEvent($delete, $replace));
}
}