Author: allyb
Date: 2010-04-28 20:58:26 +0200 (Wed, 28 Apr 2010)
New Revision: 29306
Added:
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthEditDetailsForm.class.php
Log:
Added a form to let users edit their details
Added:
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthEditDetailsForm.class.php
===================================================================
---
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthEditDetailsForm.class.php
(rev 0)
+++
plugins/sfEasyAuthPlugin/branches/2010-02-18_integration-of-doctrine/lib/form/sfEasyAuthEditDetailsForm.class.php
2010-04-28 18:58:26 UTC (rev 29306)
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Form to let users edit their sfEasyAuth details
+ *
+ * The new password is not compulsory, but both fields must match, and
+ * the current password must be set only to update the password
+ *
+ * This form won't let users edit their profiles. To use profiles, create a
form
+ * that merges this form along with a form derived from your profile form.
+ *
+ * Save the profile form and this form.
+ *
+ * @author al
+ *
+ */
+class sfEasyAuthEditDetailsForm extends BasesfEasyAuthUserForm
+{
+ public function configure()
+ {
+ if (!$this->getObject())
+ {
+ throw new InvalidArgumentException("The EditDetails form must be
+ invoked with an sfEasyAuthUser object");
+ }
+
+ $this->useFields(
+ array(
+ 'email',
+ 'password'
+ )
+ );
+
+ $this->widgetSchema->setNameFormat('edit[%s]');
+
+ $this->widgetSchema['current_password'] = new sfWidgetFormInputPassword();
+ $this->widgetSchema->moveField('current_password',
sfWidgetFormSchema::BEFORE, 'password');
+ $this->widgetSchema->setHelp('current_password', 'Please enter your
password to edit your profile');
+
+ $this->widgetSchema['password'] = new sfWidgetFormInputPassword(
+ array('label' => 'New password')
+ );
+ $this->widgetSchema['confirm_password'] = new sfWidgetFormInputPassword(
+ array('label' => 'Confirm new password')
+ );
+
+ $this->validatorSchema['email'] = new sfValidatorEmail(
+ array(
+ 'max_length' => 255
+ )
+ );
+ $this->validatorSchema['current_password'] = new sfValidatorString(
+ array(
+ 'max_length' => 255
+ )
+ );
+ $this->validatorSchema['password'] = new sfValidatorString(
+ array(
+ 'max_length' => 255,
+ 'required' => false
+ )
+ );
+ $this->validatorSchema['confirm_password'] = new sfValidatorString(
+ array(
+ 'max_length' => 255,
+ 'required' => false
+ )
+ );
+
+ $this->mergePostValidator(
+ new sfValidatorCallback(
+ array(
+ 'callback' => array($this, 'validateCurrentPassword')
+ ),
+ array('invalid' => 'You didn\'t enter your current password correctly.
+ Please try again.')
+ )
+ );
+
+ $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.'
+ )
+ )
+ );
+ }
+
+ /**
+ * Validates that the user entered their current password correctly
+ *
+ * @param <type> $validator
+ * @param <type> $value
+ * @param <type> $arguments
+ */
+ public function validateCurrentPassword($validator, $value, $arguments)
+ {
+ if (!$this->getObject()->checkPassword($value['current_password']))
+ {
+ throw new sfValidatorError($validator, 'invalid');
+ }
+
+ return $value;
+ }
+}
--
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.