I use FOSUserBundle with Symfony. When I use this in access_control: - { path: ^/, role: ROLE_USER }
my CSS is not entirely well displayed. I have 2 calls to my CSS in my layout.html.twig:
{% set bootstrap_style = client.styles.front.stylesheet %}
<link rel="stylesheet" href="{{ asset('bundles/portalfront/css/bootstrap.' ~ bootstrap_style ~ '.css' ) }}" />
Then I have :
{% stylesheets filter="cssrewrite"
'bundles/portalfront/css/font-awesome.min.css'
'bundles/portalfront/css/style.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
This second call seems to be corrupted when I use - { path: ^/, role: ROLE_USER }
but works very fine if I use - { path: ^/$, role: ROLE_USER }
Here is my security.yml :
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/, role: ROLE_USER }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
When I say it's corrupted, I mean all the styles are not applied and when I inspect the files in chrome debug I see html code instead of CSS code in my .css file. And another thing disturbing is that my bootstrap style which is well applied, seems to be called many times. Maybe we have here a sort of redirecting which corrupt the CSS files not entirely loaded.
NOTE: I have this problem ONLY in DEV mode, absolutely no problem in Production.
I found the solution here :
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/368
The problem is that you have to disable route of debug toolbar in your firewall like this :
// security.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
Be sure to add dev firewal BEFORE main firewall.