Neeraj
Neeraj

Reputation: 9145

FOSUserBundle for admin and front end

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.

Upvotes: 1

Views: 2039

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52463

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.

Upvotes: 2

Related Questions