예제 #1
0
 public function AjaxHelpdeskLogin()
 {
     setcookie('aft-cache-ctrl', '', time() - 3600);
     $sTenantHash = trim($this->getParamValue('TenantHash', ''));
     if ($this->oApiCapability->isHelpdeskSupported()) {
         $sEmail = trim($this->getParamValue('Email', ''));
         $sPassword = trim($this->getParamValue('Password', ''));
         $bSignMe = '1' === (string) $this->getParamValue('SignMe', '0');
         if (0 === strlen($sEmail) || 0 === strlen($sPassword)) {
             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);
         }
         try {
             $oHelpdeskUser = $this->oApiIntegrator->loginToHelpdeskAccount($mIdTenant, $sEmail, $sPassword);
             if ($oHelpdeskUser && !$oHelpdeskUser->Blocked) {
                 $this->oApiIntegrator->setHelpdeskUserAsLoggedIn($oHelpdeskUser, $bSignMe);
                 return $this->TrueResponse(null, __FUNCTION__);
             }
         } catch (\Exception $oException) {
             $iErrorCode = \ProjectCore\Notifications::UnknownError;
             if ($oException instanceof \CApiManagerException) {
                 switch ($oException->getCode()) {
                     case \Errs::HelpdeskManager_AccountSystemAuthentication:
                         $iErrorCode = \ProjectCore\Notifications::HelpdeskSystemUserExists;
                         break;
                     case \Errs::HelpdeskManager_AccountAuthentication:
                         $iErrorCode = \ProjectCore\Notifications::AuthError;
                         break;
                     case \Errs::HelpdeskManager_UnactivatedUser:
                         $iErrorCode = \ProjectCore\Notifications::HelpdeskUnactivatedUser;
                         break;
                     case \Errs::Db_ExceptionError:
                         $iErrorCode = \ProjectCore\Notifications::DataBaseError;
                         break;
                 }
             }
             throw new \ProjectCore\Exceptions\ClientException($iErrorCode);
         }
     }
     return $this->FalseResponse(null, __FUNCTION__);
 }