Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-01-10 01:17:53 +0300
committerOlivier Paroz <github@oparoz.com>2015-01-10 01:17:53 +0300
commit87a17f50f391ad32aa32cb6ff0a4d2c281469285 (patch)
tree472fd1c80beba7dc0a5fd640c634c288403c2794 /middleware
parent02b79f6bb28b7c9bbdb251670abaa26f1578aff4 (diff)
Some code and PHPdoc optimisations
Diffstat (limited to 'middleware')
-rw-r--r--middleware/checkmiddleware.php29
-rw-r--r--middleware/tokencheckmiddleware.php5
2 files changed, 21 insertions, 13 deletions
diff --git a/middleware/checkmiddleware.php b/middleware/checkmiddleware.php
index ba461a62..2c64c7f9 100644
--- a/middleware/checkmiddleware.php
+++ b/middleware/checkmiddleware.php
@@ -90,20 +90,33 @@ abstract class CheckMiddleware extends Middleware {
)
);
- $acceptHtml = stripos($this->request->getHeader('Accept'), 'html');
- if ($acceptHtml === false) {
- $response = $this->sendJsonResponse($acceptHtml, $code);
- } else {
- $response = $this->sendHtmlResponse($message, $code);
- }
-
- return $response;
+ return $this->computeResponse($message, $code);
}
throw $exception;
}
/**
+ * Decides which type of response to send
+ *
+ * @param string $message
+ * @param int $code
+ *
+ * @return JSONResponse|RedirectResponse|TemplateResponse
+ */
+ private function computeResponse($message, $code) {
+ $acceptHtml = stripos($this->request->getHeader('Accept'), 'html');
+ if ($acceptHtml === false) {
+ $response = $this->sendJsonResponse($acceptHtml, $code);
+ } else {
+ $response = $this->sendHtmlResponse($message, $code);
+ }
+
+ return $response;
+
+ }
+
+ /**
* Redirects the client to an error page or shows an authentication form
*
* @param string $message
diff --git a/middleware/tokencheckmiddleware.php b/middleware/tokencheckmiddleware.php
index fcfe8f90..fda61d57 100644
--- a/middleware/tokencheckmiddleware.php
+++ b/middleware/tokencheckmiddleware.php
@@ -88,10 +88,8 @@ class TokenCheckMiddleware extends CheckMiddleware {
public function beforeController($controller, $methodName) {
$token = $this->request->getParam('token');
$password = $this->request->getParam('password');
-
// This needs to be done here as the Dispatcher does not call our reflector
$this->reflector->reflect($controller, $methodName);
-
$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
$isGuest = $this->reflector->hasAnnotation('Guest');
@@ -99,13 +97,10 @@ class TokenCheckMiddleware extends CheckMiddleware {
if (!$token) {
$this->noTokenFound();
} else { // We have a token
-
// Let's see if it's linked to a valid resource
$this->checkToken($token);
-
// Let's see if the user needs to provide a password
$this->checkAuthorisation($password);
-
// Let's see if we can set up the environment for the controller
$this->setupTokenBasedEnv();
}