X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fcontroller%2Fclass_BaseController.php;h=db7521a562e57dd851e36323390dbb8d33b63d5b;hb=5203f9bd014ad46fbc7ee54e7223dcd46e14e3b4;hp=3b0d24c18cd3f878fdd0880b07bc4448fcea3209;hpb=f68c0d147585336bb415878accdff5c2af6882f8;p=core.git diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index 3b0d24c1..db7521a5 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -84,6 +84,92 @@ class BaseController extends BaseFrameworkSystem implements Registerable { $responseInstance->flushBuffer(); } + /** + * Handles the given request and response, redirects to login_failed if + * UserAuthorizationException is thrown. + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function genericHanleRequestLoginFailedRedirect (Requestable $requestInstance, Responseable $responseInstance) { + // Get the "form action" + $formAction = $requestInstance->getRequestElement('form'); + + // Get command instance from resolver + $commandInstance = $this->getResolverInstance()->resolveCommand($formAction); + + // 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(); + } + + /* + * Is the request still valid? Post filters shall only be executed of + * the request is valid + */ + if ($requestInstance->isRequestValid()) { + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Execute *very* generic ppost filters + $this->executePostFilters($requestInstance, $responseInstance); + } // END - if + + // Flush the buffer out + $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 *