Question

I want to use a single form to login normal users and admins, i have a flag on entity 'isAdmin'. If it's an admin redirect to panel and set ROLE_ADMIN, if not redirect to site and set ROLE_USER.

this is possible, have other method to do this?

Was it helpful?

Solution

Check the console commands for fosuserbundle, you can "promote" a user with the ROLE_ADMIN. On every login he'll be assigned with that role automatically.

It won't be working with a "isAdmin" flag on your Model Entity, more likely to use a mechanism provided by fosuserbundle itself (didn't dig into that myself to be honest).

You also might want to check out https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/groups.md

OTHER TIPS

That seems to make no sense at all. You should set the user's role on registration not on login.

When user loggs in you can retrieve its object from database and get the role attribute to decide which view to load.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top