Skip to content

Commit

Permalink
Remove remember me functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Dec 12, 2021
1 parent 6fbeafb commit 4164c88
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 93 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -35,11 +35,6 @@ parameters:
count: 2
path: src/Command/RoleCommand.php

-
message: "#^Binary operation \"\\.\" between 'security…' and array\\|bool\\|float\\|int\\|string\\|null results in an error\\.$#"
count: 4
path: src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php

-
message: "#^Binary operation \"\\.\" between 'security\\.user…' and array\\|bool\\|float\\|int\\|string\\|null results in an error\\.$#"
count: 2
Expand Down
33 changes: 0 additions & 33 deletions src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Form/Type/LoginFormType.php
Expand Up @@ -12,7 +12,6 @@
namespace Nucleos\UserBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand Down Expand Up @@ -51,11 +50,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'autocomplete' => 'password',
],
])
->add('_remember_me', CheckboxType::class, [
'label' => 'security.login.remember_me',
'required' => false,
'value' => 'on',
])
->add('_target_path', HiddenType::class)
;

Expand Down
2 changes: 0 additions & 2 deletions src/NucleosUserBundle.php
Expand Up @@ -15,7 +15,6 @@

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
use Nucleos\UserBundle\DependencyInjection\Compiler\InjectRememberMeServicesPass;
use Nucleos\UserBundle\DependencyInjection\Compiler\InjectUserCheckerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -27,7 +26,6 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new InjectUserCheckerPass());
$container->addCompilerPass(new InjectRememberMeServicesPass());

$this->addRegisterMappingsPass($container);
}
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/security.php
Expand Up @@ -40,7 +40,6 @@
new Reference('security.user_checker'),
new Reference('security.authentication.session_strategy'),
new Reference('request_stack'),
null,
])

->alias(LoginManagerInterface::class, 'nucleos_user.security.login_manager')
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/translations/NucleosUserBundle.de.xlf
Expand Up @@ -17,10 +17,6 @@
<source>security.login.password</source>
<target>Passwort</target>
</trans-unit>
<trans-unit id="security.login.remember_me">
<source>security.login.remember_me</source>
<target>An mich erinnern</target>
</trans-unit>
<trans-unit id="security.login.submit">
<source>security.login.submit</source>
<target>Anmelden</target>
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/translations/NucleosUserBundle.en.xlf
Expand Up @@ -17,10 +17,6 @@
<source>security.login.password</source>
<target>Password</target>
</trans-unit>
<trans-unit id="security.login.remember_me">
<source>security.login.remember_me</source>
<target>Remember me</target>
</trans-unit>
<trans-unit id="security.login.submit">
<source>security.login.submit</source>
<target>Log in</target>
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/translations/NucleosUserBundle.es.xlf
Expand Up @@ -17,10 +17,6 @@
<source>security.login.password</source>
<target>Contraseña</target>
</trans-unit>
<trans-unit id="security.login.remember_me">
<source>security.login.remember_me</source>
<target>Recordar</target>
</trans-unit>
<trans-unit id="security.login.submit">
<source>security.login.submit</source>
<target>Entrar</target>
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/translations/NucleosUserBundle.fr.xlf
Expand Up @@ -17,10 +17,6 @@
<source>security.login.password</source>
<target>Mot de passe</target>
</trans-unit>
<trans-unit id="security.login.remember_me">
<source>security.login.remember_me</source>
<target>Se souvenir de moi</target>
</trans-unit>
<trans-unit id="security.login.submit">
<source>security.login.submit</source>
<target>Connexion</target>
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/translations/NucleosUserBundle.ru.xlf
Expand Up @@ -17,10 +17,6 @@
<source>security.login.password</source>
<target>Пароль</target>
</trans-unit>
<trans-unit id="security.login.remember_me">
<source>security.login.remember_me</source>
<target>Запомнить меня</target>
</trans-unit>
<trans-unit id="security.login.submit">
<source>security.login.submit</source>
<target>Войти</target>
Expand Down
11 changes: 1 addition & 10 deletions src/Security/LoginManager.php
Expand Up @@ -19,7 +19,6 @@
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;

final class LoginManager implements LoginManagerInterface
Expand All @@ -32,20 +31,16 @@ final class LoginManager implements LoginManagerInterface

private RequestStack $requestStack;

private ?RememberMeServicesInterface $rememberMeService;

public function __construct(
TokenStorageInterface $tokenStorage,
UserCheckerInterface $userChecker,
SessionAuthenticationStrategyInterface $sessionStrategy,
RequestStack $requestStack,
RememberMeServicesInterface $rememberMeService = null
RequestStack $requestStack
) {
$this->tokenStorage = $tokenStorage;
$this->userChecker = $userChecker;
$this->sessionStrategy = $sessionStrategy;
$this->requestStack = $requestStack;
$this->rememberMeService = $rememberMeService;
}

public function logInUser(string $firewallName, UserInterface $user, Response $response = null): void
Expand All @@ -57,10 +52,6 @@ public function logInUser(string $firewallName, UserInterface $user, Response $r

if (null !== $request) {
$this->sessionStrategy->onAuthentication($request, $token);

if (null !== $response && null !== $this->rememberMeService) {
$this->rememberMeService->loginSuccess($request, $response, $token);
}
}

$this->tokenStorage->setToken($token);
Expand Down
21 changes: 5 additions & 16 deletions tests/Security/LoginManagerTest.php
Expand Up @@ -23,26 +23,25 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;

final class LoginManagerTest extends TestCase
{
public function testLogInUserWithRequestStack(): void
{
$loginManager = $this->createLoginManager('main');
$loginManager = $this->createLoginManager();
$loginManager->logInUser('main', $this->mockUser());
}

public function testLogInUserWithRememberMeAndRequestStack(): void
{
$response = $this->getMockBuilder(Response::class)->getMock();

$loginManager = $this->createLoginManager('main', $response);
$loginManager = $this->createLoginManager($response);
$loginManager->logInUser('main', $this->mockUser(), $response);
}

private function createLoginManager(string $firewallName, Response $response = null): LoginManager
private function createLoginManager(Response $response = null): LoginManager
{
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();

Expand All @@ -59,7 +58,7 @@ private function createLoginManager(string $firewallName, Response $response = n
->with(static::isInstanceOf(UserInterface::class))
;

$request = $this->getMockBuilder(Request::class)->getMock();
$request = new Request();

$sessionStrategy = $this->getMockBuilder(SessionAuthenticationStrategyInterface::class)->getMock();
$sessionStrategy
Expand All @@ -75,17 +74,7 @@ private function createLoginManager(string $firewallName, Response $response = n
->willReturn($request)
;

$rememberMe = null;
if (null !== $response) {
$rememberMe = $this->getMockBuilder(RememberMeServicesInterface::class)->getMock();
$rememberMe
->expects(static::once())
->method('loginSuccess')
->with($request, $response, static::isInstanceOf(TokenInterface::class))
;
}

return new LoginManager($tokenStorage, $userChecker, $sessionStrategy, $requestStack, $rememberMe);
return new LoginManager($tokenStorage, $userChecker, $sessionStrategy, $requestStack);
}

/**
Expand Down

0 comments on commit 4164c88

Please sign in to comment.