Introduced genericHanleRequestLoginAreaFailedRedirect()
authorRoland Haeder <roland@mxchange.org>
Tue, 7 Apr 2015 14:40:24 +0000 (16:40 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 7 Apr 2015 14:40:24 +0000 (16:40 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/main/controller/class_BaseController.php
inc/classes/main/controller/html/login/class_HtmlLoginAreaController.php

index d195c9e76bd21972997495f7a2b5f7a39562dc23..db7521a562e57dd851e36323390dbb8d33b63d5b 100644 (file)
@@ -130,6 +130,46 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
                $responseInstance->flushBuffer();
        }
 
                $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
         *
        /**
         * Private method to initialize a given filter chain
         *
index 0c7725c0de7e639980c0c09002ad1a1c63458158..375bdeeaf5db8aba3ef32d65403fddc488bb4b90 100644 (file)
@@ -70,35 +70,11 @@ class HtmlLoginAreaController extends BaseController implements Controller {
         * @return      void
         */
        public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
         * @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);
        }
 }
 
        }
 }