Author: allyb
Date: 2010-02-21 13:16:38 +0100 (Sun, 21 Feb 2010)
New Revision: 28162
Added:
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationEmailAsUsernameForm.class.php
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationForm.class.php
Log:
Created some basic forms for registration
Added:
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationEmailAsUsernameForm.class.php
===================================================================
---
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationEmailAsUsernameForm.class.php
(rev 0)
+++
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationEmailAsUsernameForm.class.php
2010-02-21 12:16:38 UTC (rev 28162)
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A simpler registration form. A user's username will be set to
+ * their email address.
+ *
+ * @see sfEasyAuthRegistrationForm
+ * @author al
+ *
+ */
+class sfEasyAuthRegistrationEmailAsUsernameForm extends
sfEasyAuthRegistrationForm
+{
+ public function configure()
+ {
+ parent::configure();
+
+ $this->useFields(
+ array(
+ 'email',
+ 'password',
+ 'confirm_password'
+ )
+ );
+
+ $this->widgetSchema->setHelp('email', 'You\'ll need this to log in.');
+ }
+
+ /**
+ * Set the email address as the user name
+ *
+ * (non-PHPdoc)
+ * @see addon/sfFormObject#save()
+ */
+ public function save($con = null)
+ {
+ $this->getObject()->setUsername($this->getValue('email'));
+ return parent::save($con);
+ }
+}
Added:
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationForm.class.php
===================================================================
---
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationForm.class.php
(rev 0)
+++
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthRegistrationForm.class.php
2010-02-21 12:16:38 UTC (rev 28162)
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Registration form for sfEasyAuth.
+ *
+ * This form won't create or save a profile. To use profiles, create a form
+ * that merges this form along with a form derived from your profile form.
+ *
+ * Save the profile form first, then call setProfileId() on the user
+ * object, passing in the profile object's ID.
+ *
+ * @author al
+ *
+ */
+class sfEasyAuthRegistrationForm extends BasesfEasyAuthUserForm
+{
+ public function configure()
+ {
+ if (!$this->getOption('credential'))
+ {
+ throw new InvalidArgumentException("The 'credential' option is
mandatory. New users
+ will be assigned the specified credentials. Give an array to
+ specify multiple credentials");
+ }
+
+ $this->useFields(
+ array(
+ 'username',
+ 'email',
+ 'password'
+ )
+ );
+
+ $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
+ $this->widgetSchema['confirm_password'] = new sfWidgetFormInputPassword();
+
+ $this->widgetSchema->setNameFormat('registration[%s]');
+
+ $this->validatorSchema['email'] = new sfValidatorEmail(
+ array(
+ 'max_length' => 255
+ )
+ );
+ $this->validatorSchema['password'] = new sfValidatorString(
+ array(
+ 'max_length' => 255
+ )
+ );
+ $this->validatorSchema['confirm_password'] = new sfValidatorString(
+ array(
+ 'max_length' => 255
+ )
+ );
+
+ $this->mergePostValidator(
+ new sfValidatorSchemaCompare(
+ 'confirm_password',
+ sfValidatorSchemaCompare::IDENTICAL,
+ 'password',
+ array(),
+ array('invalid' => 'Your passwords don\'t match. Please enter them
again.')
+ )
+ );
+
+ $this->mergePostValidator(
+ new sfValidatorDoctrineUnique(
+ array(
+ 'model' => 'sfEasyAuthUser',
+ 'column' => 'email'
+ ),
+ array(
+ 'invalid' => 'An account with that email address already exists.
Please ' .
+ 'enter a different one.'
+ )
+ )
+ );
+
+ $this->mergePostValidator(
+ new sfValidatorDoctrineUnique(
+ array(
+ 'model' => 'sfEasyAuthUser',
+ 'column' => 'username'
+ ),
+ array(
+ 'invalid' => 'An account with that username already exists. Please '
.
+ 'enter a different one.'
+ )
+ )
+ );
+ }
+
+ /**
+ * Override the save method to set the user type
+ *
+ * (non-PHPdoc)
+ * @see addon/sfFormObject#save()
+ */
+ public function save($con = null)
+ {
+ $credentials = $this->getOption('credential');
+ if (is_array($credentials))
+ {
+ foreach ($credentials as $credential)
+ {
+ $this->getObject()->addCredential($credential);
+ }
+ }
+ else
+ {
+ $this->getObject()->addCredential($credentials);
+ }
+
+ return parent::save($con);
+ }
+}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.