# sfDoctrineUserPlugin #
## About ##
This plugin provides a starting point for anyone needing a quick full user in any application. It creates a user which has a sfGuardUser.
This user then has the following properties.
* sfGuardUser
* Multiple Groups
* Multiple permissions
* username
* password
* sfUserUser
* Multiple Email Addresses
* Multiple Addresses
* Multiple Phone Numbers
* Multiple Instant Messaging Accounts
* Multiple Billing Records
* Multiple Note Records
Gives an admin page to edit all properties of a user on one page in a clean fashion
## Dependencies ##
[sfDoctrineGuardPlugin](http://www.symfony-project.com/plugins/sfDoctrineGuardPlugin)
## Installation ##
For all options, execute the commands shown from the root of your project.
### Single Export ###
This means you'll get the files only and you'll not be able to update using subversion
svn export http://svn.symfony-project.com/plugins/sfDoctrineUserPlugin/branches/1.0 ./plugins/sfDoctrineUserPlugin
### Single Checkout##
This means you'll get the files and will manually have to update using subversion
svn checkout http://svn.symfony-project.com/plugins/sfDoctrineUserPlugin/branches/1.0 ./plugins/sfDoctrineUserPlugin
### Automatic Checkout ###
If you are already using subversion for your project, and want to automatically include the latest version of this plugin on each svn update, the correct way to include the sfDoctrineUserPlugin repository is to define svn:externals.
Go to your symfony project
svn propedit svn:externals plugins
in this file add a line containing
sfDoctrineUserPlugin http://svn.symfony-project.com/plugins/sfDoctrineUserPlugin/branches/1.0
### Browse Source Code ###
[sfDoctrineUserPlugin](http://trac.symfony-project.com/browser/plugins/sfDoctrineUserPlugin)
## To Use ##
Edit the applications myUser.class.php of any application you want to be able to access the extended users information
[php]
# /apps/%%APPLICATION%%/data/lib/myUser.class.php
// Default line 3
class myUser extends sfBasicSecurityUser
// New line 3 for user with sfDoctrineUserPlugin
class myUser extends sfUserSecurityUser
### Fixture Files ###
The plugin comes with two fixture files for your use. In order to use them copy them from /sfDoctrineUserPlugin/data/fixtures/ to your projects fixture directory (/data/fixtures/). You should also remove the .sample extension from the file when copying it to your fixture directory.
* settings.yml.sample
* This file contains all the object types (AddressType, PhoneType, etc) as well as the Countries and States. This file will be useful for most projects and probably needed to use.
* user.yml.sample
* This file contains a sample of a User and can be useful for development and/or testing. You will probably not want to load this in a live environment. You'll notice how the User has a relationship to the sfDoctrineGuardPlugin's sfGuardUser. In order for this to load correctly you will have to use the sample fixture file from sfDoctrineGuardPlugin as well.
### Backend Modules ###
The plugin contains a module for each object the model. Especially useful will be the modules for editing the object types such as sfUserAddressType which has the types of Address of the Address object may be. (ie. Home, Business, PO Box)
Update the settings.yml file of your backend application to enable the modules you would like to use
[yaml]
enabled_modules: [sfUserAddressType, sfUserCreditCardType, sfUserEmailAddressType, sfUserImAccountType, sfUserPhoneType, sfUserCountry, sfUserState, sfUserAddress, sfUserBilling, sfUserEmailAddress, sfUserImAccount, sfUserPhone, sfUserUser, sfUserAdvancedUser, sfUserSimpleUser ]
#### sfUserAdvancedUser ####
### Frontend Help ###
The plugin contains some forms which should be of help when using this plugin.
One the forms, sfUserSimpleRegistrationForm gives you a form to use when registering a new user. It contains the User properties, the sfGuardUser properties, as well as one of each Object property for the user.
To use it simply call it from your action
[php]
# /apps/frontend/registration/actions/actions.class.php
class registrationActions extends sfActions
{
public function executeRegistration(sfWebRequest $request)
{
$this->form = new sfUserSimpleRegistrationForm();
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('registration'));
if ($this->form->isValid()) {
$this->form->save();
ProjectConfiguration::getActive()->loadHelpers('Url');
$this->getUser()->setFlash('new_user_id', $this->form->getObject()->getId());
$this->redirect(url_for('@signup_thank_you'));
}
}
}
}
You could also extend this class if you did not want to ask the user for all the properties..
The example below does not have the need to ask for the instant messanging account
[php]
# /apps/frontend/registration/lib/form/myRegistrationForm.class.php
class myRegistrationForm extends sfUserSimpleRegistrationForm
{
public function configure()
{
parent::configure();
unset($this['sf_user_im_account']);
}
}
# /apps/frontend/registration/actions/actions.class.php
class registrationActions extends sfActions
{
public function executeRegistration(sfWebRequest $request)
{
$this->form = new myRegistrationForm();
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('registration'));
if ($this->form->isValid()) {
$this->form->save();
ProjectConfiguration::getActive()->loadHelpers('Url');
$this->getUser()->setFlash('new_user_id', $this->form->getObject()->getId());
$this->redirect(url_for('@signup_thank_you'));
}
}
}
}
## Caveats ##
### Email Address Validation ###
By default the Doctrine Email Validator is more stict than the Symfony Email Validator.
Therefore it is possible for an email to pass through the symfony email validator but throw an exception with the Doctrine Email Validator.
If you would like to turn of mx record checking in the Doctrine Email Validator update you sfUserAddress class to look like the following
[php]
#/lib/model/doctrine/sfDoctrineUserPlugin/sfUserEmailAddress.class.php
class sfUserEmailAddress extends PluginsfUserEmailAddress
{
public function setTableDefinition()
{
parent::setTableDefinition();
$this->hasColumn('address', 'string', 128, array('type' => 'string', 'length' => 128, 'email' => array('check_mx' => false)));
}
}
### Adding fields to sfUserUser ###
If you would like to add an additional field to sfUserUser it's as the above code.
In the example below I add a gender field of type ENUM
[php]
#/lib/model/doctrine/sfDoctrineUserPlugin/sfUserUser.class.php
class sfUserUser extends PluginsfUserUser
{
public function setTableDefinition()
{
parent::setTableDefinition();
$this->hasColumn('sex', 'enum', null, array('values' => array(0 => 'Male', 1 => 'Female')));
}
}
## Screenshots ##
### sfUserSimpleUser Admin Module ###
This is editing or creating a new user with the Simple User Module which just uses sfUserSimpleUserForm. It can be extended and used within your frontend application for registration very easily.
![sfUserSimpleUser Admin Module](http://svn.symfony-project.com/plugins/sfDoctrineUserPlugin/doc/branches/1.2/readme/sfUserSimpleUserEditScreenshot.png "sfUserSimpleUser Admin Module")
### sfUserAdvancedUser Admin Module ###
This is editing or creating a new user with the Advanced User Module which just uses sfUserAdminAdvancedUserForm which extends sfUserAdvancedUserForm.
I've done this in order to display the plain text dates at the bottom which you probably wouldn't want in a frontend application.
![sfUserAdvanceUser Admin Module](http://svn.symfony-project.com/plugins/sfDoctrineUserPlugin/doc/branches/1.2/readme/sfUserAdvancedUserEditScreenshot.png "sfUserAdminAdvancedUser Admin Module")