Getting Started With FOSUserBundle ================================== The Symfony Security component provides a flexible security framework that allows you to load users from configuration, a database, or anywhere else you can imagine. The FOSUserBundle builds on top of this to make it quick and easy to store users in a database. So, if you need to persist and fetch the users in your system to and from a database, then you're in the right place. Prerequisites ------------- This version of the bundle requires Symfony 2.1+. If you are using Symfony 2.0.x, please use the 1.2.x releases of the bundle. Translations ~~~~~~~~~~~~ If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config. .. code-block:: yaml # app/config/config.yml framework: translator: ~ For more information about translations, check `Symfony documentation`_. Installation ------------ Installation is a quick (I promise!) 7 step process: 1. Download FOSUserBundle using composer 2. Enable the Bundle 3. Create your User class 4. Configure your application's security.yml 5. Configure the FOSUserBundle 6. Import FOSUserBundle routing 7. Update your database schema Step 1: Download FOSUserBundle using composer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Require the bundle with composer: .. code-block:: bash $ composer require friendsofsymfony/user-bundle "~1.3" Composer will install the bundle to your project's ``vendor/friendsofsymfony/user-bundle`` directory. Step 2: Enable the bundle ~~~~~~~~~~~~~~~~~~~~~~~~~ Enable the bundle in the kernel:: .. caution:: ``user`` is a reserved keyword in the SQL standard. If you need to use reserved words, surround them with backticks, *e.g.* ``@ORM\Table(name="`user`")`` b) MongoDB User class ..................... If you're persisting your users via the Doctrine MongoDB ODM, then your ``User`` class should live in the ``Document`` namespace of your bundle and look like this to start:: Only three configuration values are required to use the bundle: * The type of datastore you are using (``orm``, ``mongodb``, ``couchdb`` or ``propel``). * The firewall name which you configured in Step 4. * The fully qualified class name (FQCN) of the ``User`` class which you created in Step 3. .. caution:: When using one of the Doctrine implementation, you need either to use the ``auto_mapping`` option of the corresponding bundle (done by default for DoctrineBundle in the standard distribution) or to activate the mapping for FOSUserBundle otherwise the base mapping will be ignored. Step 6: Import FOSUserBundle routing files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now that you have activated and configured the bundle, all that is left to do is import the FOSUserBundle routing files. By importing the routing files you will have ready made pages for things such as logging in, creating users, etc. .. configuration-block:: .. code-block:: yaml # app/config/routing.yml fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml" fos_user_profile: resource: "@FOSUserBundle/Resources/config/routing/profile.xml" prefix: /profile fos_user_register: resource: "@FOSUserBundle/Resources/config/routing/registration.xml" prefix: /register fos_user_resetting: resource: "@FOSUserBundle/Resources/config/routing/resetting.xml" prefix: /resetting fos_user_change_password: resource: "@FOSUserBundle/Resources/config/routing/change_password.xml" prefix: /profile .. code-block:: xml .. note:: In order to use the built-in email functionality (confirmation of the account, resetting of the password), you must activate and configure the SwiftmailerBundle. Step 7: Update your database schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now that the bundle is configured, the last thing you need to do is update your database schema because you have added a new entity, the ``User`` class which you created in Step 4. For ORM run the following command. .. code-block:: bash $ php app/console doctrine:schema:update --force For MongoDB users you can run the following command to create the indexes. .. code-block:: bash $ php app/console doctrine:mongodb:schema:create --index For Propel 1 users you have to install the `TypehintableBehavior`_ before to build your model. First, install it: .. code-block:: bash composer require willdurand/propel-typehintable-behavior You now can run the following command to create the model: .. code-block:: bash $ php app/console propel:build .. note:: To create SQL, run the command ``propel:build --insert-sql`` or use migration commands if you have an existing schema in your database. You now can login at ``http://app.com/app_dev.php/login``! Next Steps ~~~~~~~~~~ Now that you have completed the basic installation and configuration of the FOSUserBundle, you are ready to learn about more advanced features and usages of the bundle. The following documents are available: .. toctree:: :maxdepth: 1 overriding_templates overriding_controllers overriding_forms user_manager command_line_tools logging_by_username_or_email form_type emails groups doctrine overriding_validation canonicalizer custom_storage_layer configuration_reference adding_invitation_registration .. _security component documentation: https://symfony.com/doc/current/book/security.html .. _Symfony documentation: https://symfony.com/doc/current/book/translation.html .. _TypehintableBehavior: https://github.com/willdurand/TypehintableBehavior