Symfony Tutorial: FOSUserBundle Command Line Tools

 For some reason, Symfony removed the FOSUserBundle Command Line Tools from its site. If you are like me that has several projects depending of that bundle, you don't have the time to migrate from it, and someone needs to deploy those projects as soon as possible, you might be caught off guard. That's why I'm creating this post, as a copy for those who might need it.

Create a User

You can use the fos:user:create command to create a new user for your application. The command takes three arguments, the username, email, and password for the user you are creating.

For example if you wanted to create a user with username testuser, with email test@example.com and password p@ssword, you would run the command as follows.

php bin/console fos:user:create testuser test@example.com p@ssword
view raw fos_create_user hosted with ❤ by GitHub

If any of the required arguments are not passed to the command, an interactive prompt will ask you to enter them. For example, if you ran the command as follows, then you would be prompted to enter the email and password for the user you want to create.

php bin/console fos:user:create testuser

There are two options that you can pass to the command as well. They are --super-admin and --inactive.

Specifying the --super-admin option will flag the user as a super admin when the user is created. A super admin has access to any part of your application. An example is provided below:

php bin/console fos:user:create adminuser --super-admin
view raw fos_super_admin hosted with ❤ by GitHub

If you specify the --inactive option, then the user that you create will no be able to login until he is activated.

php bin/console fos:user:create testuser --inactive



Activate a User

Activate a UserThe fos:user:activate command activates an inactive user. The only argument that the command requires is the username of the user who should be activated. If no username is specified then an interactive prompt will ask you to enter one. An example of using this command is listed below.

php bin/console fos:user:activate testuser


No comments

Powered by Blogger.