I'm new to Symfony, I follow a tutorial, the part about security and user management but I'm stucked with a problem that seems to come from my routing.
I just created a login form that is actually working, when I go on /app_dev.php/login
, the form shows up, I can fill it, but when I submit it, I got the following error :
No route found for "GET /" (from "http://dev-05/ANTOINE/Symfony/web/app_dev.php/login")
404 Not Found - NotFoundHttpException
1 linked Exception:
ResourceNotFoundException »
After getting this error, if I go back on the home page, I can see I am connected, so it's working, but the redirection is not .
According to the documentation, this comes from the routing that might be wrongly configured, but I don't know where I made a mistake.
Here's my form, my security.yml and my routing.yml files :
{% extends "AKMUserBundle::layout.html.twig" %}
{% block akmuser_body %}
{% if error %}
<div class="alert alert-danger">{{ error.message }}</div>
{% endif %}
<form action="{{ path('login_check') }}" method="post">
<label for="username">Login : </label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<label for="password">Mot de passe :</label>
<input type="password" id="password" name="_password" />
<br />
<input type="submit" value="Connexion" />
</form>
{% endblock %}
security.yml :
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: ['ROLE_USER'] }
admin: { password: adminpass, roles: ['ROLE_ADMIN'] }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
form_login:
login_path: login
check_path: login_check
logout:
path: logout
target: /platform
routing.yml :
akm_platform:
resource: "@AKMPlatformBundle/Resources/config/routing.yml"
prefix: /platform
login:
path: /login
defaults:
_controller: AKMUserBundle:Security:login
login_check:
path: /login_check
logout:
path: /logout
I'm aware that .yml
files are very sensitive and need 4 spaces instead of the usual indentation, so I rewrote the files line by line, with the spaces, but it is still not working.
I hope someone can help me :p If you need some informations don't hesitate!
Edit : Here is my result of the php bin/console debug:router
Edit 2 : To get rid of my problem I just had to add the default_target_path in my security.yml :
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: ['ROLE_USER'] }
admin: { password: adminpass, roles: ['ROLE_ADMIN'] }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
form_login:
login_path: login
check_path: login_check
default_target_path: akm_platform_home
logout:
path: logout
target: /platform