Example #1
0
 /**
  * @return array
  */
 public function AjaxSystemLogin()
 {
     setcookie('aft-cache-ctrl', '', time() - 3600);
     $sEmail = trim((string) $this->getParamValue('Email', ''));
     $sIncLogin = (string) $this->getParamValue('IncLogin', '');
     $sIncPassword = (string) $this->getParamValue('IncPassword', '');
     $sLanguage = (string) $this->getParamValue('Language', '');
     $bSignMe = '1' === (string) $this->getParamValue('SignMe', '0');
     try {
         \CApi::Plugin()->RunHook('webmail-login-custom-data', array($this->getParamValue('CustomRequestData', null)));
     } catch (\Exception $oException) {
         \CApi::LogEvent(\EEvents::LoginFailed, $sEmail);
         throw $oException;
     }
     $oSettings =& \CApi::GetSettings();
     $sAtDomain = trim($oSettings->GetConf('WebMail/LoginAtDomainValue'));
     if ((\ELoginFormType::Email === (int) $oSettings->GetConf('WebMail/LoginFormType') || \ELoginFormType::Both === (int) $oSettings->GetConf('WebMail/LoginFormType')) && 0 === strlen($sAtDomain) && 0 < strlen($sEmail) && !\MailSo\Base\Validator::EmailString($sEmail)) {
         throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AuthError);
     }
     if (\ELoginFormType::Login === (int) $oSettings->GetConf('WebMail/LoginFormType') && 0 < strlen($sAtDomain)) {
         $sEmail = \api_Utils::GetAccountNameFromEmail($sIncLogin) . '@' . $sAtDomain;
         $sIncLogin = $sEmail;
     }
     if (0 === strlen($sIncPassword) || 0 === strlen($sEmail . $sIncLogin)) {
         \CApi::LogEvent(\EEvents::LoginFailed, $sEmail);
         \CApi::Log($sEmail, \ELogLevel::Full, 'a-');
         \CApi::Log($sIncLogin, \ELogLevel::Full, 'a-');
         \CApi::Log($sIncPassword, \ELogLevel::Full, 'a-');
         throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter);
     }
     try {
         if (0 === strlen($sLanguage)) {
             $sLanguage = $this->oApiIntegrator->getLoginLanguage();
         }
         $oAccount = $this->oApiIntegrator->loginToAccount($sEmail, $sIncPassword, $sIncLogin, $sLanguage);
     } 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;
             }
         }
         \CApi::LogEvent(\EEvents::LoginFailed, $sEmail);
         throw new \ProjectCore\Exceptions\ClientException($iErrorCode, $oException, $oException instanceof \CApiBaseException ? $oException->GetPreviousMessage() : ($oException ? $oException->getMessage() : ''));
     }
     if ($oAccount instanceof \CAccount) {
         $sAuthToken = '';
         $bSetAccountAsLoggedIn = true;
         \CApi::Plugin()->RunHook('api-integrator-set-account-as-logged-in', array(&$bSetAccountAsLoggedIn));
         if ($bSetAccountAsLoggedIn) {
             \CApi::LogEvent(\EEvents::LoginSuccess, $oAccount);
             $sAuthToken = $this->oApiIntegrator->setAccountAsLoggedIn($oAccount, $bSignMe);
         }
         return $this->DefaultResponse($oAccount, __FUNCTION__, array('AuthToken' => $sAuthToken));
     }
     \CApi::LogEvent(\EEvents::LoginFailed, $oAccount);
     throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AuthError);
 }