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-05 07:26:50 +0300
committerOlivier Paroz <github@oparoz.com>2015-01-05 07:26:50 +0300
commit74a31853c85724a178686f794aeb1c617a833504 (patch)
tree7e09b4c1d5ccb476cd8286fd0589c016f3407117 /middleware
parent8f0637385e82d94b78196f754b5febcb91351be5 (diff)
First round of fixes
Diffstat (limited to 'middleware')
-rw-r--r--middleware/checkmiddleware.php1
-rw-r--r--middleware/tokencheckmiddleware.php96
2 files changed, 68 insertions, 29 deletions
diff --git a/middleware/checkmiddleware.php b/middleware/checkmiddleware.php
index e10c41b6..f460ac9a 100644
--- a/middleware/checkmiddleware.php
+++ b/middleware/checkmiddleware.php
@@ -18,7 +18,6 @@ use OCP\IURLGenerator;
use OCP\ILogger;
use OCP\IRequest;
-use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
diff --git a/middleware/tokencheckmiddleware.php b/middleware/tokencheckmiddleware.php
index 0ec4585f..24a66e71 100644
--- a/middleware/tokencheckmiddleware.php
+++ b/middleware/tokencheckmiddleware.php
@@ -97,43 +97,83 @@ class TokenCheckMiddleware extends CheckMiddleware {
if ($isPublicPage && !$isGuest) {
if (!$token) {
- throw new CheckException(
- "Can't access a public resource without a token",
- Http::STATUS_NOT_FOUND
- );
+ $this->noTokenFound();
} else { // We have a token
// Let's see if it's linked to a valid resource
- try {
- $this->environmentService->checkToken($token);
- } catch (ServiceException $exception) {
- throw new CheckException(
- $exception->getMessage(),
- $exception->getCode()
- );
- }
+ $this->checkToken($token);
// Let's see if the user needs to provide a password
- try {
- $this->environmentService->checkAuthorisation($password);
- } catch (ServiceException $exception) {
- throw new CheckException(
- $exception->getMessage(),
- $exception->getCode()
- );
- }
+ $this->checkAuthorisation($password);
// Let's see if we can set up the environment for the controller
- try {
- $this->environmentService->setupTokenBasedEnv();
- } catch (ServiceException $exception) {
- throw new CheckException(
- $exception->getMessage(),
- $exception->getCode()
- );
- }
+ $this->setupTokenBasedEnv();
}
}
}
+ /**
+ * Throws an exception because no token was provided
+ *
+ * @throws CheckException
+ */
+ private function noTokenFound() {
+ throw new CheckException(
+ "Can't access a public resource without a token",
+ Http::STATUS_NOT_FOUND
+ );
+ }
+
+ /**
+ * Makes sure we have a valid token, linked to a valid resource
+ *
+ * @param string $token
+ *
+ * @throws CheckException
+ */
+ private function checkToken($token) {
+ try {
+ $this->environmentService->checkToken($token);
+ } catch (ServiceException $exception) {
+ throw new CheckException(
+ $exception->getMessage(),
+ $exception->getCode()
+ );
+ }
+ }
+
+ /**
+ * Checks if a password is required or if the one supplied is working
+ *
+ * @param $password
+ *
+ * @throws CheckException
+ */
+ private function checkAuthorisation($password) {
+ try {
+ $this->environmentService->checkAuthorisation($password);
+ } catch (ServiceException $exception) {
+ throw new CheckException(
+ $exception->getMessage(),
+ $exception->getCode()
+ );
+ }
+ }
+
+ /**
+ * Sets up the environment based on the received token
+ *
+ * @throws CheckException
+ */
+ private function setupTokenBasedEnv() {
+ try {
+ $this->environmentService->setupTokenBasedEnv();
+ } catch (ServiceException $exception) {
+ throw new CheckException(
+ $exception->getMessage(),
+ $exception->getCode()
+ );
+ }
+ }
+
} \ No newline at end of file