Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##actions.class.php
- protected function processForm(sfWebRequest $request, sfForm $form)
- {
- $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
- if ($form->isValid())
- {
- $sf_guard_user = $form->save();
- $this->redirect('settings/index');
- }
- }
- ##SettingsForm.class.php (Master form)
- class SettingsForm extends sfGuardUserForm
- {
- public function configure()
- {
- // Remove all widgets we don't want to show
- unset(
- $this['is_active'],
- $this['is_super_admin'],
- $this['updated_at'],
- $this['groups_list'],
- $this['permissions_list'],
- $this['last_login'],
- $this['created_at'],
- $this['salt'],
- $this['algorithm'],
- $this['applications_list'],
- $this['organizations_list'],
- $this['user_id']
- );
- // Setup proper password validation with confirmation
- $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
- $this->validatorSchema['password']->setOption('required', true);
- $this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
- $this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password'];
- $this->setDefaults(
- array(
- 'password'=>'',
- 'password_confirmation' => ''
- )
- );
- $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_confirmation', array(), array('invalid' => 'Both passwords must be the same.')));
- // Embed attempt 1 - WORKS
- $this->embedAppForms();
- // Embed attempt 2 - WORKS
- $sub_form = new SubForm($this->getObject()->getSubObject());
- $this->embedForm('SubObject',$sub_form );
- }
- protected function embedAppForms(){
- $user = $this->getObject();
- foreach($user->getApplications() as $application){
- $options = $this->options;
- $options['user'] = $user;
- $options['application'] = $application;
- $object_class = $application->getObjectName();
- $getter_function = 'get'.$object_class;
- $form_class = $object_class.'SettingsForm';
- $object = $user->$getter_function();
- $appform = new $form_class($object,$options);
- $this->embedForm($object_class,$appform);
- unset($options);
- }
- }
- }
- ##SubObject.class.php - The object of the embedded form
- class SubObject extends BaseSubObject
- {
- public function getObjectPassword(){
- $salt = $this->_get('salt');
- $password = $this->_get('object_password');
- /* MAGIC returns $decrypted_password*/
- return $decrypted_password;
- }
- public function setObjectPassword($password){
- if(!$salt = $this->_get('salt')){
- $this->setSalt();
- $salt = $this->_get('salt');
- }
- $salted_password = $password.$salt;
- /* MAGIC returns $encoded_password */
- $this->_set('google_password',$encoded_password);
- }
- public function setSalt(){
- $salt = uniqid();
- return $this->_set('salt',$salt);
- }
- }
Add Comment
Please, Sign In to add comment