From 57bbef1a14d5222562ec63d82f8d1d568352fc1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 29 Sep 2015 22:47:03 +0200 Subject: [PATCH] Handle NamedUserExceptions in RequestHandler --- .../system/request/RequestHandler.class.php | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 1e00a3b2d5..cdd73edf09 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -4,6 +4,7 @@ use wcf\system\application\ApplicationHandler; use wcf\system\cache\builder\ControllerCacheBuilder; use wcf\system\exception\AJAXException; use wcf\system\exception\IllegalLinkException; +use wcf\system\exception\NamedUserException; use wcf\system\exception\SystemException; use wcf\system\menu\page\PageMenu; use wcf\system\SingletonFactory; @@ -102,41 +103,47 @@ class RequestHandler extends SingletonFactory { * @param boolean $isACPRequest */ public function handle($application = 'wcf', $isACPRequest = false) { - $this->isACPRequest = $isACPRequest; - - if (!RouteHandler::getInstance()->matches()) { - if (ENABLE_DEBUG_MODE) { - throw new SystemException("Cannot handle request, no valid route provided."); - } - else { - throw new IllegalLinkException(); - } - } - - // build request - $this->buildRequest($application); - - // handle offline mode - if (!$isACPRequest && defined('OFFLINE') && OFFLINE) { - if (!WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode') && !$this->activeRequest->isAvailableDuringOfflineMode()) { - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) { - throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS); + try { + $this->isACPRequest = $isACPRequest; + + if (!RouteHandler::getInstance()->matches()) { + if (ENABLE_DEBUG_MODE) { + throw new SystemException("Cannot handle request, no valid route provided."); } else { - @header('HTTP/1.1 503 Service Unavailable'); - WCF::getTPL()->assign(array( - 'templateName' => 'offline', - 'templateNameApplication' => 'wcf' - )); - WCF::getTPL()->display('offline'); + throw new IllegalLinkException(); + } + } + + // build request + $this->buildRequest($application); + + // handle offline mode + if (!$isACPRequest && defined('OFFLINE') && OFFLINE) { + if (!WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode') && !$this->activeRequest->isAvailableDuringOfflineMode()) { + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) { + throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS); + } + else { + @header('HTTP/1.1 503 Service Unavailable'); + WCF::getTPL()->assign(array( + 'templateName' => 'offline', + 'templateNameApplication' => 'wcf' + )); + WCF::getTPL()->display('offline'); + } + + exit; } - - exit; } + + // start request + $this->activeRequest->execute(); + } + catch (NamedUserException $e) { + $e->show(); + exit; } - - // start request - $this->activeRequest->execute(); } /** -- 2.20.1