2
votes

I am using the FOSUserBundle, I just want to prefix all its routes with a '/account'. I have a UserBundle inheriting from FOSUserBundle:

<?php
//UserBundle.php

namespace UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class UserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

Defined this controller with a prefix in my routes :

# app/config/routing.yml
user:
    resource: "@UserBundle/Resources/config/routing.yml"
    prefix:   /account

And import FOS routes in my bundle:

#UserBundle/config/routing.yml
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    prefix:   /user

I tried to override file by file, and all the route one by one, via XML (to override the parent files) or via yml. I always have the routes well defined (output of bin/console debug:route --show-controllers):

  fos_user_security_login             GET|POST   ANY      ANY    /account/login                             FOSUserBundle:Security:login                          
  fos_user_security_check             POST       ANY      ANY    /account/login_check                       FOSUserBundle:Security:check                          
  fos_user_security_logout            GET|POST   ANY      ANY    /account/logout                            FOSUserBundle:Security:logout                         
  fos_user_profile_show               GET        ANY      ANY    /account/profile/                          FOSUserBundle:Profile:show                            
  fos_user_profile_edit               GET|POST   ANY      ANY    /account/profile/edit                      FOSUserBundle:Profile:edit                            
  fos_user_registration_register      GET|POST   ANY      ANY    /account/register/                         FOSUserBundle:Registration:register                   
  fos_user_registration_check_email   GET        ANY      ANY    /account/register/check-email              FOSUserBundle:Registration:checkEmail                 
  fos_user_registration_confirm       GET        ANY      ANY    /account/register/confirm/{token}          FOSUserBundle:Registration:confirm                    
  fos_user_registration_confirmed     GET        ANY      ANY    /account/register/confirmed                FOSUserBundle:Registration:confirmed                  
  fos_user_resetting_request          GET        ANY      ANY    /account/resetting/request                 FOSUserBundle:Resetting:request                       
  fos_user_resetting_send_email       POST       ANY      ANY    /account/resetting/send-email              FOSUserBundle:Resetting:sendEmail                     
  fos_user_resetting_check_email      GET        ANY      ANY    /account/resetting/check-email             FOSUserBundle:Resetting:checkEmail                    
  fos_user_resetting_reset            GET|POST   ANY      ANY    /account/resetting/reset/{token}           FOSUserBundle:Resetting:reset                         
  fos_user_change_password            GET|POST   ANY      ANY    /account/profile/change-password           FOSUserBundle:ChangePassword:changePassword

But when I redirect to the route 'fos_user_security_login' I am redirected to '/login' and not '/account/login'

If you have any idea why, I'll be please to know :p EDIT : Here is the firewalls and acls in the security.yml

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        pattern: ^/
        form_login:
            check_path: /account/login_check
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            # if you are using Symfony < 2.8, use the following config instead:
            # csrf_provider: form.csrf_provider
        logout:
            path:   /account/logout
            target: /account/login
        anonymous:    true

access_control:
    # authorise to login and reset password for everyone
    - { path: ^/account, role: IS_AUTHENTICATED_ANONYMOUSLY }
2
show your security.ymlMichał G
Added it at the end of the post ;)Thiryn
A template overriding works, but it appears that a controller overriding does not work eitherThiryn

2 Answers

1
votes

I found the problem, I was because of poor right management. I tried to access / and redirect it to /account/login, but I did not have the ACL set for the / path, meaning it redirected me automatically to /login, giving me the impression the problem was in my redirection.

0
votes

Probably the problem is in

#UserBundle/config/routing.yml
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    prefix:   /user

It's probably overriding the login route you're defining with the one by default. Try adding in the routing file this:

login:
    path: /account/login
    defaults: { _controller: FOSUserBundle:Security:login }

login_check:
    path:  /account/login_check
    defaults: { _controller: FOSUserBundle:Security:check }

After you import all the routes, or add only the routes you need from the FOSUserBundle. You can get them from the FOSUserBundle/Resources/config/routing/all.xml under vendor directory.