Guest User

Untitled

a guest
Jan 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. ##actions.class.php
  2. protected function processForm(sfWebRequest $request, sfForm $form)
  3. {
  4. $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  5. if ($form->isValid())
  6. {
  7. $sf_guard_user = $form->save();
  8. $this->redirect('settings/index');
  9. }
  10. }
  11.  
  12. ##SettingsForm.class.php (Master form)
  13. class SettingsForm extends sfGuardUserForm
  14. {
  15. public function configure()
  16. {
  17. // Remove all widgets we don't want to show
  18. unset(
  19. $this['is_active'],
  20. $this['is_super_admin'],
  21. $this['updated_at'],
  22. $this['groups_list'],
  23. $this['permissions_list'],
  24. $this['last_login'],
  25. $this['created_at'],
  26. $this['salt'],
  27. $this['algorithm'],
  28. $this['applications_list'],
  29. $this['organizations_list'],
  30. $this['user_id']
  31. );
  32. // Setup proper password validation with confirmation
  33. $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
  34. $this->validatorSchema['password']->setOption('required', true);
  35. $this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
  36. $this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password'];
  37. $this->setDefaults(
  38. array(
  39. 'password'=>'',
  40. 'password_confirmation' => ''
  41. )
  42. );
  43. $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_confirmation', array(), array('invalid' => 'Both passwords must be the same.')));
  44.  
  45. // Embed attempt 1 - WORKS
  46. $this->embedAppForms();
  47.  
  48. // Embed attempt 2 - WORKS
  49. $sub_form = new SubForm($this->getObject()->getSubObject());
  50. $this->embedForm('SubObject',$sub_form );
  51. }
  52.  
  53. protected function embedAppForms(){
  54. $user = $this->getObject();
  55. foreach($user->getApplications() as $application){
  56. $options = $this->options;
  57. $options['user'] = $user;
  58. $options['application'] = $application;
  59. $object_class = $application->getObjectName();
  60. $getter_function = 'get'.$object_class;
  61. $form_class = $object_class.'SettingsForm';
  62. $object = $user->$getter_function();
  63. $appform = new $form_class($object,$options);
  64. $this->embedForm($object_class,$appform);
  65. unset($options);
  66. }
  67. }
  68. }
  69.  
  70. ##SubObject.class.php - The object of the embedded form
  71. class SubObject extends BaseSubObject
  72. {
  73. public function getObjectPassword(){
  74. $salt = $this->_get('salt');
  75. $password = $this->_get('object_password');
  76. /* MAGIC returns $decrypted_password*/
  77. return $decrypted_password;
  78. }
  79. public function setObjectPassword($password){
  80. if(!$salt = $this->_get('salt')){
  81. $this->setSalt();
  82. $salt = $this->_get('salt');
  83. }
  84. $salted_password = $password.$salt;
  85. /* MAGIC returns $encoded_password */
  86. $this->_set('google_password',$encoded_password);
  87. }
  88. public function setSalt(){
  89. $salt = uniqid();
  90. return $this->_set('salt',$salt);
  91. }
  92. }
Add Comment
Please, Sign In to add comment