1

I am new to Symfony2. I am trying to use FOSUserBundle for user authentication.

Is it possible to use single FOSUserBundle for admin as well as front end section? If yes, then what changes i will need to make at script level?

What i want is:

1. if i access url http://localhost/symfony/admin/ then i should be redirected to http://localhost/symfony/admin/login if admin is not logged in and after successful login, i should be redirected to http://localhost/symfony/admin/

2. if i access url http://localhost/symfony/profile/ then i should be redirected to http://localhost/symfony/login if user is not logged in and after successful login, i should be redirected to http://localhost/symfony/profile/.

By default FOSUserBundle create user as administrator. So what change need to place in to let bundle create user role for front end automatically and admin role for admin section.

Neeraj
  • 8,625
  • 18
  • 60
  • 89

1 Answers1

2

You need to override the authentication-success listener in your security configuration to have user's redirected to different pages after login depending on their roles.

Have a look at this answer and maybe find some inspiration by looking at symfony's DefaultAuthenticationSuccessHandler.

Further you will need to override the access-denied handler ( see this answer ) to have user's get redirected to different login pages depending on the url they're trying to access without being authenticated.

Community
  • 1
  • 1
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • Ok, but configuration/changes would be required to keep two separate login page (one for admin and another for normal user of front end)? – Neeraj Sep 12 '13 at 09:52
  • if you want to use a bundle for your multi-user implementation you can give [PUGXMultiUserBundle](https://github.com/PUGX/PUGXMultiUserBundle) a try. – Nicolai Fröhlich Sep 12 '13 at 09:56