예제 #1
0
 /**
  * @param string $sLogin
  * @param string $sPassword
  * @return bool
  */
 public function AuthLogin($sLogin, $sPassword)
 {
     $oSettings = null;
     $oSettings =& CApi::GetSettings();
     $sDemoLogin = CApi::GetConf('demo.adminpanel.login', '');
     $sLogin = trim($sLogin);
     $sPassword = trim($sPassword);
     if (empty($sLogin) || empty($sPassword)) {
         return false;
     }
     if ($oSettings->GetConf('Common/AdminLogin') === $sLogin && $this->oWebmailApi->validateAdminPassword($sPassword)) {
         $this->setAdminAccessType(AP_SESS_AUTH_TYPE_SUPER_ADMIN);
         return true;
     } else {
         if (CApi::GetConf('demo.adminpanel.enable', false) && 0 < strlen($sDemoLogin) && $sDemoLogin === CPost::get('AdmloginInput')) {
             $this->setAdminAccessType(AP_SESS_AUTH_TYPE_SUPER_ADMIN_ONLYREAD);
             return true;
         } else {
             if ($this->oAdminPanel->PType() && $this->oAdminPanel->RType()) {
                 $iTenantId = $this->oAdminPanel->CallModuleFunction('CProModule', 'GetTenantIdByLoginPassword', array($sLogin, $sPassword));
                 if (0 < $iTenantId) {
                     $oTenant = $this->oAdminPanel->CallModuleFunction('CProModule', 'getTenantById', array($iTenantId));
                     if ($oTenant) {
                         /* @var $oTenant CTenant */
                         if (0 < $oTenant->Expared && $oTenant->Expared < \time()) {
                             $sDesc = '<div style="display: block; margin: 0px auto; font: 11pt Verdana,sans-serif; width: 340px; padding: 20px; color: #777;">';
                             $sDesc .= '<h2 style="color: #D35A5A; font-weight: normal; font-size: 16pt;">' . CAPi::I18N('ADMIN_PANEL/YOUR_SUBSCRIPTION_IS_EXPIRED') . '</h2>';
                             if (0 < strlen($oTenant->PayUrl)) {
                                 $sDesc .= '<p>' . CAPi::I18N('ADMIN_PANEL/TO_RENEW_FOLLOW_LINK') . ' <a target="_blank" href="' . ap_Utils::AttributeQuote($oTenant->PayUrl) . '">' . $oTenant->PayUrl . '</a></p>';
                             }
                             $sDesc .= '</div>';
                             CSession::Set('SESSION_LOGIN_WARNING', $sDesc);
                             return true;
                         }
                         $this->setAdminAccessType(AP_SESS_AUTH_TYPE_TENANT);
                         $this->setTenantAccessId($iTenantId);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
예제 #2
0
 /**
  * @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);
 }