Esempio n. 1
0
 /**
  * @return array
  */
 public function AjaxAccountRegister()
 {
     $sName = trim((string) $this->getParamValue('Name', ''));
     $sEmail = trim((string) $this->getParamValue('Email', ''));
     $sPassword = trim((string) $this->getParamValue('Password', ''));
     $sQuestion = trim((string) $this->getParamValue('Question', ''));
     $sAnswer = trim((string) $this->getParamValue('Answer', ''));
     \CApi::Plugin()->RunHook('webmail-register-custom-data', array($this->getParamValue('CustomRequestData', null)));
     $oSettings =& \CApi::GetSettings();
     if (!$oSettings || !$oSettings->GetConf('Common/AllowRegistration')) {
         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidInputParameter);
     }
     if (0 === strlen($sPassword) || 0 === strlen($sEmail) || 0 === strlen($sQuestion) || 0 === strlen($sAnswer)) {
         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidInputParameter);
     }
     $oAccount = $this->oApiUsers->GetAccountOnLogin($sEmail);
     if ($oAccount instanceof \CAccount) {
         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidInputParameter);
         // TODO
     }
     try {
         $oAccount = $this->oApiWebMail->CreateAccountProcess($sEmail, $sPassword, '', array('FriendlyName' => $sName, 'Question1' => $sQuestion, 'Answer1' => $sAnswer), true);
         if ($oAccount instanceof \CAccount) {
             \CApi::Plugin()->RunHook('api-integrator-login-success-post-create-account-call', array(&$oAccount));
         } else {
             $oException = $this->oApiWebMail->GetLastException();
             \CApi::Plugin()->RunHook('api-integrator-login-error-post-create-account-call', array(&$oException));
             throw is_object($oException) ? $oException : new \CApiManagerException(Errs::WebMailManager_AccountCreateOnLogin);
         }
     } catch (\Exception $oException) {
         $iErrorCode = \ProjectSeven\Notifications::UnknownError;
         if ($oException instanceof \CApiManagerException) {
             switch ($oException->getCode()) {
                 case \Errs::WebMailManager_AccountDisabled:
                 case \Errs::WebMailManager_AccountWebmailDisabled:
                     $iErrorCode = \ProjectSeven\Notifications::AuthError;
                     break;
                 case \Errs::UserManager_AccountAuthenticationFailed:
                 case \Errs::WebMailManager_AccountAuthentication:
                 case \Errs::WebMailManager_NewUserRegistrationDisabled:
                 case \Errs::WebMailManager_AccountCreateOnLogin:
                 case \Errs::Mail_AccountAuthentication:
                 case \Errs::Mail_AccountLoginFailed:
                     $iErrorCode = \ProjectSeven\Notifications::AuthError;
                     break;
                 case \Errs::UserManager_AccountConnectToMailServerFailed:
                 case \Errs::WebMailManager_AccountConnectToMailServerFailed:
                 case \Errs::Mail_AccountConnectToMailServerFailed:
                     $iErrorCode = \ProjectSeven\Notifications::MailServerError;
                     break;
                 case \Errs::UserManager_LicenseKeyInvalid:
                 case \Errs::UserManager_AccountCreateUserLimitReached:
                 case \Errs::UserManager_LicenseKeyIsOutdated:
                 case \Errs::TenantsManager_AccountCreateUserLimitReached:
                     $iErrorCode = \ProjectSeven\Notifications::LicenseProblem;
                     break;
                 case \Errs::Db_ExceptionError:
                     $iErrorCode = \ProjectSeven\Notifications::DataBaseError;
                     break;
             }
         }
         throw new \ProjectSeven\Exceptions\ClientException($iErrorCode, $oException, $oException instanceof \CApiBaseException ? $oException->GetPreviousMessage() : ($oException ? $oException->getMessage() : ''));
     }
     if ($oAccount instanceof \CAccount) {
         $this->oApiIntegrator->SetAccountAsLoggedIn($oAccount);
         return $this->TrueResponse($oAccount, __FUNCTION__);
     }
     throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::AuthError);
 }