I am having this rather common problem of Symfony login failing with this error message:
Unable to find the controller for path "/auth/login_check".
The common answer to this problem is that the login_check route isn't behind the firewall, but in my case it is! Here are my config files:
app/config/security.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
auth_area:
pattern: ^/auth/(login|login_check)
anonymous: ~
secured_area:
pattern: ^/
form_login:
login_path: /auth/login
check_path: /auth/login_check
logout:
path: /auth/logout
target: /
app/config/routing.yml
login:
pattern: /auth/login
defaults: { _controller: AuthBundle:Default:login }
login_check:
pattern: /auth/login_check
logout:
pattern: /auth/logout
AuthBundle/Controller/DefaultController.php
public function loginAction()
{
$form = $this->createForm(new UserType(), new User());
return $this->render('AuthBundle:Default:login.html.twig', array(
'form' => $form->createView(),
'action' => $this->generateUrl('login_check'),
));
}
AuthBundle/Form/Type/UserType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username', 'text', array('label' => 'Login:'));
$builder->add('password', 'password', array('label' => 'Password:'));
}
AuthBundle/Resources/views/Default/login.html.twig
...
<form action="{{ action }}" method="POST">
{{ form_widget(form) }}
<input type="submit" value="Login" />
</form>
...
My form is created with the route login_check as target (/auth/login_check URL).
The secured_area firewall is supposed to match all URLs, so /auth/login_check should be in it. Yet, I keep getting this error. What am I doing wrong?