Skip to content

Commit 8ac9640

Browse files
carlcasboltjaviereguiluz
authored andcommitted
LoginFormAuthenticator example updated
RouterInterface has been replaced with UrlGeneratorInterface
1 parent 5c48d08 commit 8ac9640

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

security/form_login_setup.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ a traditional HTML form that submits to ``/login``:
174174

175175
use Symfony\Component\HttpFoundation\RedirectResponse;
176176
use Symfony\Component\HttpFoundation\Request;
177-
use Symfony\Component\Routing\RouterInterface;
177+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
178178
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
179179
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
180180
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
@@ -185,21 +185,22 @@ a traditional HTML form that submits to ``/login``:
185185
use Symfony\Component\Security\Csrf\CsrfToken;
186186
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
187187
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
188+
use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
188189
use Symfony\Component\Security\Http\Util\TargetPathTrait;
189190

190-
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
191+
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
191192
{
192193
use TargetPathTrait;
193194

194195
private $entityManager;
195-
private $router;
196+
private $urlGenerator;
196197
private $csrfTokenManager;
197198
private $passwordEncoder;
198199

199-
public function __construct(EntityManagerInterface $entityManager, RouterInterface $router, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $passwordEncoder)
200+
public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $passwordEncoder)
200201
{
201202
$this->entityManager = $entityManager;
202-
$this->router = $router;
203+
$this->urlGenerator = $urlGenerator;
203204
$this->csrfTokenManager = $csrfTokenManager;
204205
$this->passwordEncoder = $passwordEncoder;
205206
}
@@ -253,13 +254,13 @@ a traditional HTML form that submits to ``/login``:
253254
return new RedirectResponse($targetPath);
254255
}
255256

256-
// For example : return new RedirectResponse($this->router->generate('some_route'));
257+
// For example : return new RedirectResponse($this->urlGenerator->generate('some_route'));
257258
throw new \Exception('TODO: provide a valid redirect inside '.__FILE__);
258259
}
259260

260261
protected function getLoginUrl()
261262
{
262-
return $this->router->generate('app_login');
263+
return $this->urlGenerator->generate('app_login');
263264
}
264265
}
265266

0 commit comments

Comments
 (0)