A really simple sfGuard with user profile setup
May 12th, 2010 - kaore - Symfony
When you start trying to see how something works, it’s always nice to see the thing in action and try it out in a simple environment where nothing else can interfere. In the case of this post, the subject is the sfGuard plugin and in particular how it is possible to use it together with an application specific User model. This post gives you a setup with a working sfGuard plugin in a Doctrine & symfony 1.4.4 environment. To have it work, simply decompress this file, do a symfony doctrine:build –all –and-load, configure your server to point to the project and that should be enough.
The model used in this setup is a simple list of users which can be accessed through a user module, where only the access of the show action is restricted to authenticated users. sfGuardAuth signin and signout actions & modules are also used.
Let me know if something doesn’t work as it should.
These posts where helpful:
- The readme of the plugin itself
- More details are given on this page. They are definitely worth a read (or 10).
Here is a summary of the steps taken to reach this setup at its downloadable form. The details can be found in the references given above:
- Create a project, a frontend app, a schema giving details of a User table and a user module
- Get the plugin and put it in the plugins folder
- Enable the plugin in the ProjectConfiguration.class.php file, as well as the settings.yml file of the application
- In the same settings.yml list the login module and action to be used
- In the schema.yml, modifications are made to link the User table to the sfGuard model.
- In the app.yml of the app, the User table should be set as the Profile class of the sfGuard model
- The show action of the module is secured using a config/security.yml file of the module
- The forms need to be adapted as well, an sfGuardUserForm is created to extend the PluginsfGuardUserForm, using the username and password fields only (the others don’t need to be input by the user… after that, the newly created form can be embedded in the User form using the embedRelation function… the form template of the module needs to be adapted as well to take into account these changes.
- On last little thing: signin and signout links are set in the layout, using the plugin default routes