diff options
author | Olivier Paroz <github@oparoz.com> | 2015-09-08 15:22:18 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-09-17 23:53:36 +0300 |
commit | ec6a904c8df91a614c435d48568970edc1c3c2a8 (patch) | |
tree | ea47ee52f829ccc16d45547d53e3ab6248941da4 /controller | |
parent | 4ea24d9e510d60fd483bd6643d7f0b1ade52e704 (diff) |
Don't send the error messages via GET/POST
Diffstat (limited to 'controller')
-rw-r--r-- | controller/filesapicontroller.php | 15 | ||||
-rw-r--r-- | controller/filescontroller.php | 10 | ||||
-rw-r--r-- | controller/filespubliccontroller.php | 1 | ||||
-rw-r--r-- | controller/httperror.php | 12 | ||||
-rw-r--r-- | controller/pagecontroller.php | 29 |
5 files changed, 44 insertions, 23 deletions
diff --git a/controller/filesapicontroller.php b/controller/filesapicontroller.php index 551017d5..a59e7029 100644 --- a/controller/filesapicontroller.php +++ b/controller/filesapicontroller.php @@ -14,6 +14,7 @@ namespace OCA\Gallery\Controller; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\ISession; use OCP\ILogger; use OCP\AppFramework\ApiController; @@ -38,6 +39,8 @@ class FilesApiController extends ApiController { /** @var IURLGenerator */ private $urlGenerator; + /** @var ISession */ + private $session; /** * Constructor @@ -49,6 +52,7 @@ class FilesApiController extends ApiController { * @param ConfigService $configService * @param SearchMediaService $searchMediaService * @param DownloadService $downloadService + * @param ISession $session * @param ILogger $logger */ public function __construct( @@ -59,6 +63,7 @@ class FilesApiController extends ApiController { ConfigService $configService, SearchMediaService $searchMediaService, DownloadService $downloadService, + ISession $session, ILogger $logger ) { parent::__construct($appName, $request); @@ -68,6 +73,7 @@ class FilesApiController extends ApiController { $this->configService = $configService; $this->searchMediaService = $searchMediaService; $this->downloadService = $downloadService; + $this->session = $session; $this->logger = $logger; } @@ -101,9 +107,14 @@ class FilesApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * @UseSession * * Sends the file matching the fileId * + * In case of error we send an HTML error page + * We need to keep the session open in order to be able to send the error message to the error + * page + * * @param int $fileId the ID of the file we want to download * @param string|null $filename * @@ -113,7 +124,9 @@ class FilesApiController extends ApiController { try { $download = $this->getDownload($fileId, $filename); } catch (ServiceException $exception) { - return $this->htmlError($this->urlGenerator, $this->appName, $exception); + return $this->htmlError( + $this->session, $this->urlGenerator, $this->appName, $exception + ); } return new ImageResponse($download); diff --git a/controller/filescontroller.php b/controller/filescontroller.php index 32a50d4b..1370bb95 100644 --- a/controller/filescontroller.php +++ b/controller/filescontroller.php @@ -14,6 +14,7 @@ namespace OCA\Gallery\Controller; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\ISession; use OCP\ILogger; use OCP\AppFramework\Controller; @@ -38,6 +39,8 @@ class FilesController extends Controller { /** @var IURLGenerator */ private $urlGenerator; + /** @var ISession */ + private $session; /** * Constructor @@ -49,6 +52,7 @@ class FilesController extends Controller { * @param ConfigService $configService * @param SearchMediaService $searchMediaService * @param DownloadService $downloadService + * @param ISession $session * @param ILogger $logger */ public function __construct( @@ -59,6 +63,7 @@ class FilesController extends Controller { ConfigService $configService, SearchMediaService $searchMediaService, DownloadService $downloadService, + ISession $session, ILogger $logger ) { parent::__construct($appName, $request); @@ -68,6 +73,7 @@ class FilesController extends Controller { $this->configService = $configService; $this->searchMediaService = $searchMediaService; $this->downloadService = $downloadService; + $this->session = $session; $this->logger = $logger; } @@ -114,7 +120,9 @@ class FilesController extends Controller { try { $download = $this->getDownload($fileId, $filename); } catch (ServiceException $exception) { - return $this->htmlError($this->urlGenerator, $this->appName, $exception); + return $this->htmlError( + $this->session, $this->urlGenerator, $this->appName, $exception + ); } return new ImageResponse($download); diff --git a/controller/filespubliccontroller.php b/controller/filespubliccontroller.php index 90c06a1a..32380b48 100644 --- a/controller/filespubliccontroller.php +++ b/controller/filespubliccontroller.php @@ -41,6 +41,7 @@ class FilesPublicController extends FilesController { /** * @PublicPage * @NoCSRFRequired + * @UseSession * * Sends the file matching the fileId * diff --git a/controller/httperror.php b/controller/httperror.php index 51c1d34b..b80deb92 100644 --- a/controller/httperror.php +++ b/controller/httperror.php @@ -17,6 +17,7 @@ namespace OCA\Gallery\Controller; use Exception; use OCP\IURLGenerator; +use OCP\ISession; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -53,22 +54,19 @@ trait HttpError { } /** + * @param ISession $session * @param IURLGenerator $urlGenerator * @param string $appName * @param \Exception $exception * * @return RedirectResponse */ - public function htmlError($urlGenerator, $appName, Exception $exception) { + public function htmlError($session, $urlGenerator, $appName, Exception $exception) { $message = $exception->getMessage(); $code = $this->getHttpStatusCode($exception); - + $session->set('galleryErrorMessage', $message); $url = $urlGenerator->linkToRoute( - $appName . '.page.error_page', - [ - 'message' => $message, - 'code' => $code - ] + $appName . '.page.error_page', ['code' => $code] ); return new RedirectResponse($url); diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 83172d5e..ca9e074b 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -17,6 +17,7 @@ namespace OCA\Gallery\Controller; use OCP\IURLGenerator; use OCP\IRequest; use OCP\IConfig; +use OCP\ISession; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -25,7 +26,6 @@ use OCP\AppFramework\Http\RedirectResponse; use OCA\Gallery\Environment\Environment; use OCA\Gallery\Http\ImageResponse; -use OCA\Gallery\Service\DownloadService; /** * Generates templates for the landing page from within ownCloud, the public @@ -35,18 +35,14 @@ use OCA\Gallery\Service\DownloadService; */ class PageController extends Controller { - /** - * @var Environment - */ + /** @var Environment */ private $environment; - /** - * @var IURLGenerator - */ + /** @var IURLGenerator */ private $urlGenerator; - /** - * @var IConfig - */ + /** @var IConfig */ private $appConfig; + /** @var ISession */ + private $session; /** * Constructor @@ -56,19 +52,22 @@ class PageController extends Controller { * @param Environment $environment * @param IURLGenerator $urlGenerator * @param IConfig $appConfig + * @param ISession $session */ public function __construct( $appName, IRequest $request, Environment $environment, IURLGenerator $urlGenerator, - IConfig $appConfig + IConfig $appConfig, + ISession $session ) { parent::__construct($appName, $request); $this->environment = $environment; $this->urlGenerator = $urlGenerator; $this->appConfig = $appConfig; + $this->session = $session; } /** @@ -117,7 +116,7 @@ class PageController extends Controller { $url = $this->urlGenerator->linkToRoute( $this->appName . '.files_public.download', [ - 'token' => $token, + 'token' => $token, 'fileId' => $node->getId(), 'filename' => $filename ] @@ -131,16 +130,18 @@ class PageController extends Controller { * @PublicPage * @NoCSRFRequired * @Guest + * @UseSession * * Generates an error page based on the error code * - * @param string $message * @param int $code * * @return TemplateResponse */ - public function errorPage($message, $code) { + public function errorPage($code) { $appName = $this->appName; + $message = $this->session->get('galleryErrorMessage'); + $this->session->remove('galleryErrorMessage'); $params = [ 'appName' => $appName, 'message' => $message, |