This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Security;
class EmailUserProvider extends UserProvider
{
/**
* {@inheritdoc}
*/
protected function findUser($username)
{
return $this->userManager->findUserByUsernameOrEmail($username);
}
}

View File

@@ -0,0 +1,107 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Security;
use FOS\UserBundle\Model\UserInterface;
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\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
/**
* Abstracts process for manually logging in a user.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class LoginManager implements LoginManagerInterface
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
* @var UserCheckerInterface
*/
private $userChecker;
/**
* @var SessionAuthenticationStrategyInterface
*/
private $sessionStrategy;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var RememberMeServicesInterface
*/
private $rememberMeService;
/**
* LoginManager constructor.
*
* @param TokenStorageInterface $tokenStorage
* @param UserCheckerInterface $userChecker
* @param SessionAuthenticationStrategyInterface $sessionStrategy
* @param RequestStack $requestStack
* @param RememberMeServicesInterface|null $rememberMeService
*/
public function __construct(TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker,
SessionAuthenticationStrategyInterface $sessionStrategy,
RequestStack $requestStack,
RememberMeServicesInterface $rememberMeService = null
) {
$this->tokenStorage = $tokenStorage;
$this->userChecker = $userChecker;
$this->sessionStrategy = $sessionStrategy;
$this->requestStack = $requestStack;
$this->rememberMeService = $rememberMeService;
}
/**
* {@inheritdoc}
*/
final public function logInUser($firewallName, UserInterface $user, Response $response = null)
{
$this->userChecker->checkPreAuth($user);
$token = $this->createToken($firewallName, $user);
$request = $this->requestStack->getCurrentRequest();
if (null !== $request) {
$this->sessionStrategy->onAuthentication($request, $token);
if (null !== $response && null !== $this->rememberMeService) {
$this->rememberMeService->loginSuccess($request, $response, $token);
}
}
$this->tokenStorage->setToken($token);
}
/**
* @param string $firewall
* @param UserInterface $user
*
* @return UsernamePasswordToken
*/
protected function createToken($firewall, UserInterface $user)
{
return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Security;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\HttpFoundation\Response;
interface LoginManagerInterface
{
/**
* @param string $firewallName
* @param UserInterface $user
* @param Response|null $response
*/
public function logInUser($firewallName, UserInterface $user, Response $response = null);
}

View File

@@ -0,0 +1,95 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Security;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
class UserProvider implements UserProviderInterface
{
/**
* @var UserManagerInterface
*/
protected $userManager;
/**
* Constructor.
*
* @param UserManagerInterface $userManager
*/
public function __construct(UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
{
$user = $this->findUser($username);
if (!$user) {
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
}
return $user;
}
/**
* {@inheritdoc}
*/
public function refreshUser(SecurityUserInterface $user)
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Expected an instance of FOS\UserBundle\Model\UserInterface, but got "%s".', get_class($user)));
}
if (!$this->supportsClass(get_class($user))) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), get_class($user)));
}
if (null === $reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId()))) {
throw new UsernameNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId()));
}
return $reloadedUser;
}
/**
* {@inheritdoc}
*/
public function supportsClass($class)
{
$userClass = $this->userManager->getClass();
return $userClass === $class || is_subclass_of($class, $userClass);
}
/**
* Finds a user by username.
*
* This method is meant to be an extension point for child classes.
*
* @param string $username
*
* @return UserInterface|null
*/
protected function findUser($username)
{
return $this->userManager->findUserByUsername($username);
}
}