예제 #1
0
 public function AjaxSocialRegister()
 {
     $sTenantHash = trim($this->getParamValue('TenantHash', ''));
     if ($this->oApiCapability->IsHelpdeskSupported()) {
         $sNotificationEmail = trim($this->getParamValue('NotificationEmail', ''));
         if (isset($_COOKIE["Social"])) {
             $aSocial = \CApi::DecodeKeyValues($_COOKIE["Social"]);
         } else {
             $aSocial = array('type' => '', 'id' => '', 'name' => '', 'email' => '');
         }
         $sSocialType = $aSocial['type'];
         $sSocialId = $aSocial['id'];
         $sSocialName = $aSocial['name'];
         $sSocialEmail = $aSocial['email'];
         if (0 !== strlen($sSocialEmail)) {
             $sNotificationEmail = $sSocialEmail;
         }
         if (0 === strlen($sNotificationEmail)) {
             throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidInputParameter);
         }
         $mIdTenant = $this->oApiIntegrator->GetTenantIdByHash($sTenantHash);
         if (!is_int($mIdTenant)) {
             throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidInputParameter);
         }
         $bResult = false;
         try {
             $bResult = $this->oApiIntegrator->RegisterSocialAccount($mIdTenant, $sTenantHash, $sNotificationEmail, $sSocialId, $sSocialType, $sSocialName);
         } catch (\Exception $oException) {
             $iErrorCode = \ProjectSeven\Notifications::UnknownError;
             if ($oException instanceof \CApiManagerException) {
                 switch ($oException->getCode()) {
                     case \Errs::HelpdeskManager_UserAlreadyExists:
                         $iErrorCode = \ProjectSeven\Notifications::HelpdeskUserAlreadyExists;
                         break;
                     case \Errs::HelpdeskManager_UserCreateFailed:
                         $iErrorCode = \ProjectSeven\Notifications::CanNotCreateHelpdeskUser;
                         break;
                     case \Errs::Db_ExceptionError:
                         $iErrorCode = \ProjectSeven\Notifications::DataBaseError;
                         break;
                 }
             }
             throw new \ProjectSeven\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__);
 }