public function AjaxSocialRegister() { $sTenantHash = trim($this->getParamValue('TenantHash', '')); if ($this->oApiCapability->isHelpdeskSupported()) { $sNotificationEmail = trim($this->getParamValue('NotificationEmail', '')); if (isset($_COOKIE["p7social"])) { $aSocial = \CApi::DecodeKeyValues($_COOKIE["p7social"]); } else { $aSocial = array('type' => '', 'id' => '', 'name' => '', 'email' => ''); } $sSocialType = $aSocial['type']; $sSocialId = $aSocial['id']; $sSocialName = $aSocial['name']; $sEmail = $aSocial['email']; if (0 !== strlen($sEmail)) { $sNotificationEmail = $sEmail; } if (0 === strlen($sNotificationEmail)) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter); } $mIdTenant = $this->oApiIntegrator->getTenantIdByHash($sTenantHash); if (!is_int($mIdTenant)) { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter); } $bResult = false; try { $bResult = $this->oApiIntegrator->registerSocialAccount($mIdTenant, $sTenantHash, $sNotificationEmail, $sSocialId, $sSocialType, $sSocialName); } catch (\Exception $oException) { $iErrorCode = \ProjectCore\Notifications::UnknownError; if ($oException instanceof \CApiManagerException) { switch ($oException->getCode()) { case \Errs::HelpdeskManager_UserAlreadyExists: $iErrorCode = \ProjectCore\Notifications::HelpdeskUserAlreadyExists; break; case \Errs::HelpdeskManager_UserCreateFailed: $iErrorCode = \ProjectCore\Notifications::CanNotCreateHelpdeskUser; break; case \Errs::Db_ExceptionError: $iErrorCode = \ProjectCore\Notifications::DataBaseError; break; } } throw new \ProjectCore\Exceptions\ClientException($iErrorCode); } if ($bResult) { $bResult = false; $oUser = \CApi::Manager('integrator')->getAhdSocialUser($sTenantHash, $sSocialId); if ($oUser) { \CApi::Manager('integrator')->setHelpdeskUserAsLoggedIn($oUser, false); $bResult = true; } } return $this->DefaultResponse(null, __FUNCTION__, $bResult); } return $this->FalseResponse(null, __FUNCTION__); }