From: Roland Haeder Date: Tue, 7 Apr 2015 14:40:24 +0000 (+0200) Subject: Introduced genericHanleRequestLoginAreaFailedRedirect() X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=9de57a793d0555beb99dfbcbe80503e8e29d69a9 Introduced genericHanleRequestLoginAreaFailedRedirect() Signed-off-by: Roland Häder --- diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index d195c9e7..db7521a5 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -130,6 +130,46 @@ class BaseController extends BaseFrameworkSystem implements Registerable { $responseInstance->flushBuffer(); } + /** + * Generic execute of the command: pre and post filters with redirect + * but request becomes valid after pre-filters run. + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function genericHanleRequestLoginAreaFailedRedirect (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Try to run the pre filters, if auth exceptions come through redirect here + try { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + } catch (UserAuthorizationException $e) { + // Redirect to main page + $responseInstance->redirectToConfiguredUrl('login_failed'); + + // Exit here + exit(); + } + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the pre filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } + /** * Private method to initialize a given filter chain * diff --git a/inc/classes/main/controller/html/login/class_HtmlLoginAreaController.php b/inc/classes/main/controller/html/login/class_HtmlLoginAreaController.php index 0c7725c0..375bdeea 100644 --- a/inc/classes/main/controller/html/login/class_HtmlLoginAreaController.php +++ b/inc/classes/main/controller/html/login/class_HtmlLoginAreaController.php @@ -70,35 +70,11 @@ class HtmlLoginAreaController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Try to run the pre filters, if auth exceptions come through redirect here - try { - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - } catch (UserAuthorizationException $e) { - // Redirect to main page - $responseInstance->redirectToConfiguredUrl('login_failed'); - - // Exit here - exit(); - } - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the pre filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); + /* + * Generic execute of the command: pre and post filters with redirect + * but request becomes valid after pre-filters run. + */ + $this->genericHanleRequestLoginAreaFailedRedirect($requestInstance, $responseInstance); } }