예제 #1
0
 /**
  * Updates an existing user
  *
  * @param Tx_Ajaxlogin_Domain_Model_User
  *
  * @return void
  */
 public function updateAction(Tx_Ajaxlogin_Domain_Model_User $user)
 {
     // double check if the passed user is indeed currently logged in user
     $currentUser = $this->userRepository->findCurrent();
     if ($user->getUid() != $currentUser->getUid()) {
         // no way...
         $this->forward('edit');
     }
     // TODO: clean this up and move it to the proper validators!!!
     // this much of validation shouldn't have found its way into the controller
     // START of MOVE TO VALIDATOR task
     $objectError = t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', 'user');
     $emailError = t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', 'email');
     $checkEmail = $this->userRepository->findOneByEmail($user->getEmail());
     if (!is_null($checkEmail) && $checkEmail->getUid() != $user->getUid()) {
         $emailError->addErrors(array(t3lib_div::makeInstance('Tx_Extbase_Error_Error', 'Duplicate email address', 1320783534)));
     }
     if (count($emailError->getErrors())) {
         $objectError->addErrors(array($emailError));
     }
     if (count($objectError->getErrors())) {
         $requestErrors = $this->request->getErrors();
         $requestErrors[] = $objectError;
         $this->request->setErrors($requestErrors);
         $this->forward('edit');
     }
     // END of MOVE TO VALIDATOR task
     // check submitted country
     if ($country) {
         $country = $this->countryRepository->findByCnShortEn($user->getCountry());
         if (!$country->count()) {
             $user->setCountry('');
         }
     }
     $this->userRepository->update($user);
     $this->flashMessageContainer->add('User updated');
     $this->forward('show');
 }