Zeck
Zeck

Reputation: 6579

Role based redirect?

I have login and I want to if admin login go to admin/index, if user login go to home/index page. How to do it using security.yml in Symfony 2.0 Beta1? By default, now it's redirect to http://myapp.com/app_dev.php. Please help me?

I'm put my security.yml file:

security:
   encoders:
       App\SecurityBundle\Entity\User:
           algorithm: sha512
           encode-as-base64: true
           iterations: 10

   providers:
       backend:
           entity: { class: AppSecurityBundle:User, property:
username }

   firewalls:
       backend:
           pattern: /admin/.*
           form_login:
               check_path: /login_check
               login_path: /login
           logout: true
           security: true
           anonymous: true
       public:
           pattern: /.*
           security: false

   access_control:
       - { path: /admin/.*, role: ROLE_ADMIN }
       - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }

Upvotes: 2

Views: 392

Answers (1)

Ajb
Ajb

Reputation: 1275

You could set the default_target_path under the form_login configuration directive and point it to a controller which redirects the user based on his roles.

Upvotes: 2

Related Questions