예제 #1
0
 /**
  * Creates a new user
  *
  * @param Tx_Ajaxlogin_Domain_Model_User $user A fresh User object which has not yet been added to the repository
  * @param string $password_check
  *
  * @return void
  */
 public function createAction(Tx_Ajaxlogin_Domain_Model_User $user, $password_check)
 {
     if ($user && $user->getUid()) {
         // somehow the cHash got hacked
         $this->forward('new');
     }
     if (t3lib_div::_GP('additionalInfo')) {
         // honeypot field was filled
         $this->forward('new');
     }
     // 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');
     $usernameError = t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', 'username');
     $passwordError = t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', 'password');
     $checkEmail = $this->userRepository->findOneByEmail($user->getEmail());
     $checkUsername = $this->userRepository->findOneByUsername($user->getUsername());
     if (!is_null($checkEmail)) {
         $emailError->addErrors(array(t3lib_div::makeInstance('Tx_Extbase_Error_Error', 'Duplicate email address', 1320783534)));
     }
     if (!is_null($checkUsername)) {
         $usernameError->addErrors(array(t3lib_div::makeInstance('Tx_Extbase_Error_Error', 'Duplicate username', 1320703758)));
     }
     if (strcmp($user->getPassword(), $password_check) != 0) {
         $passwordError->addErrors(array(t3lib_div::makeInstance('Tx_Extbase_Error_Error', 'Password does not match', 1320703779)));
     }
     if (count($emailError->getErrors())) {
         $objectError->addErrors(array($emailError));
     }
     if (count($usernameError->getErrors())) {
         $objectError->addErrors(array($usernameError));
     }
     if (count($passwordError->getErrors())) {
         $objectError->addErrors(array($passwordError));
     }
     if (count($objectError->getErrors())) {
         $requestErrors = $this->request->getErrors();
         $requestErrors[] = $objectError;
         $this->request->setErrors($requestErrors);
         // needed in order to trigger the JS AJAX error callback
         $this->response->setStatus(409);
         $this->forward('new');
     }
     // END of MOVE TO VALIDATOR task
     $userGroups = $this->userGroupRepository->findByUidArray(t3lib_div::intExplode(',', $this->settings['defaultUserGroups']));
     $password = $user->getPassword();
     $password = Tx_Ajaxlogin_Utility_Password::salt($password);
     foreach ($userGroups as $userGroup) {
         $user->getUsergroup()->attach($userGroup);
     }
     $user->setPassword($password);
     // add a hash to verify the account by sending an e-mail
     $user->setVerificationHash(md5(t3lib_div::generateRandomBytes(64)));
     $user->setDisable(true);
     $this->userRepository->add($user);
     $this->userRepository->_persistAll();
     $message = Tx_Extbase_Utility_Localization::translate('signup_successful', 'ajaxlogin');
     $this->flashMessageContainer->add($message, '', t3lib_FlashMessage::OK);
     $this->view->assign('user', $user);
     $emailSubject = Tx_Extbase_Utility_Localization::translate('signup_notification_subject', 'ajaxlogin', array(t3lib_div::getIndpEnv('TYPO3_HOST_ONLY')));
     $emailBodyContent = $this->view->render();
     $mail = t3lib_div::makeInstance('t3lib_mail_Message');
     $mail->setFrom(array($this->settings['notificationMail']['emailAddress'] => $this->settings['notificationMail']['sender']));
     $mail->setTo(array($user->getEmail() => $user->getName()));
     $mail->setSubject($emailSubject);
     $mail->setBody($emailBodyContent);
     $mail->send();
     $referer = t3lib_div::_GP('referer');
     $redirectUrl = t3lib_div::_GP('redirectUrl');
     $redirect_url = Tx_Ajaxlogin_Utility_RedirectUrl::findRedirectUrl($referer, $redirectUrl);
     if (!empty($redirect_url)) {
         $this->response->setHeader('X-Ajaxlogin-redirectUrl', $redirect_url);
     }
     $this->forward('info');
 }