Просмотр исходного кода

#3979 Setting to lock site for guests is working correctly sometimes

Alex Trofimov 4 лет назад
Родитель
Сommit
175f69c351
3 измененных файлов с 21 добавлено и 19 удалено
  1. 15 10
      inc/classes/BxDolPage.php
  2. 2 2
      template/scripts/BxBasePage.php
  3. 4 7
      template/scripts/BxBasePageAccount.php

+ 15 - 10
inc/classes/BxDolPage.php

@@ -565,6 +565,11 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         if(isLogged())
             BxDolAccount::getInstance()->isNeedChangePassword();
 
+        if ($this->isLockedFromUnauthenticated ($this->_aObject['uri'])) {
+            $this->redirectToLoginForm();
+            exit;
+        }
+
         if(!$oTemplate)
             $oTemplate = BxDolTemplate::getInstance();
 
@@ -676,7 +681,12 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
     /**
      * Check if page is visible.
      */
-    protected function _isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated = false)
+    protected function _isVisiblePage ($a)
+    {
+        return isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
+    }
+
+    public static function isLockedFromUnauthenticated ($sUri)
     {
         if (!isLogged() && getParam('sys_lock_from_unauthenticated') && !defined('BX_DOL_CRON_EXECUTE')) {
             $aURIs = explode(',', getParam('sys_lock_from_unauthenticated_exceptions'));
@@ -684,20 +694,15 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
                 $sVal = trim($sVal);
             });
             $aI = array_combine($aURIs, array_fill(0, count($aURIs), 1));
-            if (!preg_match('/\/oauth2\//', $_SERVER['REQUEST_URI']) /*&& !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF'])*/ && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$this->_aObject['uri']])) {
-                if ($bRedirectToLoginFormForUnauthenticated) {
-                    $this->_redirectToLoginForm();
-                }
-                else {
-                    return false;
-                }
+            if (!preg_match('/\/oauth2\//', $_SERVER['REQUEST_URI']) /*&& !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF'])*/ && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$sUri])) {
+                return true;
             }
         }
 
-        return isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
+        return false;
     }
 
-    protected function _redirectToLoginForm ()
+    public static function redirectToLoginForm ()
     {
         header("Location: " . bx_append_url_params(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login'), ['relocate' => bx_get_self_url()]));
         exit;

+ 2 - 2
template/scripts/BxBasePage.php

@@ -158,7 +158,7 @@ class BxBasePage extends BxDolPage
     {
         if (bx_get('dynamic') && ($iBlockId = (int)bx_get('pageBlock'))) {
 
-            if (!$this->_isVisiblePage($this->_aObject, true)) {
+            if (self::isLockedFromUnauthenticated($this->_aObject['uri']) || !$this->_isVisiblePage($this->_aObject)) {
                 header('HTTP/1.0 403 Forbidden');
                 exit;
             }
@@ -184,7 +184,7 @@ class BxBasePage extends BxDolPage
             exit;
         }
 
-        if (!$this->_isVisiblePage($this->_aObject, true))
+        if (!$this->_isVisiblePage($this->_aObject))
             return $this->_getPageAccessDeniedMsg ();
 
         $this->_addJsCss();

+ 4 - 7
template/scripts/BxBasePageAccount.php

@@ -102,15 +102,12 @@ class BxBasePageAccount extends BxTemplPage
         }
     }
 
-    protected function _isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated = false)
+    protected function _isVisiblePage ($a)
     {
-        if (!isLogged()) {
-            if ($bRedirectToLoginFormForUnauthenticated)
-                $this->_redirectToLoginForm();
-            else
+        if (!isLogged())
                 return false;
-        }
-        return parent::_isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated);
+
+        return parent::_isVisiblePage ($a);
     }
     
 	protected function _addJsCss()