Beispiel #1
0
 /**
  * Form to edit a user
  * User login must be set in parameter
  * @return  void
  */
 public function edit()
 {
     if (!$this->hasRequestParameter('uri')) {
         throw new Exception('Please set the user uri in request parameter');
     }
     $user = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
     $myFormContainer = new tao_actions_form_Users($this->userService->getClass($user), $user);
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $values = $myForm->getValues();
             if (!empty($values['password2']) && !empty($values['password3'])) {
                 $values[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']);
             }
             unset($values['password2']);
             unset($values['password3']);
             if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_UILG]))) {
                 unset($values[PROPERTY_USER_UILG]);
             }
             if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_DEFLG]))) {
                 unset($values[PROPERTY_USER_DEFLG]);
             }
             $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($user);
             if ($binder->bind($values)) {
                 $this->setData('message', __('User saved'));
             }
         }
     }
     $this->setData('formTitle', __('Edit a user'));
     $this->setData('myForm', $myForm->render());
     $this->setView('user/form.tpl');
 }