/** * @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 \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter); } if (0 === strlen($sPassword) || 0 === strlen($sEmail) || 0 === strlen($sQuestion) || 0 === strlen($sAnswer)) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter); } $oAccount = $this->oApiUsers->getAccountByEmail($sEmail); if ($oAccount instanceof \CAccount) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\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 = \ProjectCore\Notifications::UnknownError; if ($oException instanceof \CApiManagerException) { switch ($oException->getCode()) { case \Errs::WebMailManager_AccountDisabled: case \Errs::WebMailManager_AccountWebmailDisabled: $iErrorCode = \ProjectCore\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 = \ProjectCore\Notifications::AuthError; break; case \Errs::UserManager_AccountConnectToMailServerFailed: case \Errs::WebMailManager_AccountConnectToMailServerFailed: case \Errs::Mail_AccountConnectToMailServerFailed: $iErrorCode = \ProjectCore\Notifications::MailServerError; break; case \Errs::UserManager_LicenseKeyInvalid: case \Errs::UserManager_AccountCreateUserLimitReached: case \Errs::UserManager_LicenseKeyIsOutdated: case \Errs::TenantsManager_AccountCreateUserLimitReached: $iErrorCode = \ProjectCore\Notifications::LicenseProblem; break; case \Errs::Db_ExceptionError: $iErrorCode = \ProjectCore\Notifications::DataBaseError; break; } } throw new \ProjectCore\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 \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AuthError); }