By default, created user has role ROLE_USER
which is saved in DB like empty array converted to JSON a:0:{}
. In FOSUserBundle exists some helpful Command Line Tools. You should use Promote a User for set user ROLE_ADMIN
like this:
$ php app/console fos:user:promote username ROLE_ADMIN
After that your username
user will have access to admin panel where you can promote other users manually.
To create users with diferent ROLE
types you should write event listener for fos_user.registration.initialize
(or even fos_user.registration.success
) event, like this:
class RegistrationListener
{
public function setUserRole(UserEvent $event)
{
$request = $event->getRequest();
if (/* some conditions */) {
$user = $event->getUser();
$user->addRole('ROLE_STH');
}
}
}
Please be careful with using this listener for setting ROLE_ADMIN
. Promote a User command is intended to add role like ROLE_ADMIN
.