diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-02 16:07:57 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-02 19:05:18 +0300 |
commit | 31bc57a4e95fd5a0b25bec7e5b934110930cffd7 (patch) | |
tree | 148bb1a4b417cb5d2ae5d4913ff73ba9130e051c /lib | |
parent | d0fb26127dfebe455fc1faee7e4ef33c29bfc081 (diff) |
redirects to homepage instead showing error on blank page
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | lib/Middleware/OnlyLoggedInMiddleware.php | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3ab81811..a56671eb 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -38,7 +38,8 @@ class Application extends App { $container->registerService('OnlyLoggedInMiddleware', function (IAppContainer $c) { return new OnlyLoggedInMiddleware( $c->query('ControllerMethodReflector'), - $c->query('ServerContainer')->getUserSession() + $c->query('ServerContainer')->getUserSession(), + $c->query('ServerContainer')->getUrlGenerator() ); }); diff --git a/lib/Middleware/OnlyLoggedInMiddleware.php b/lib/Middleware/OnlyLoggedInMiddleware.php index 23abf1fa..6a3bfdf7 100644 --- a/lib/Middleware/OnlyLoggedInMiddleware.php +++ b/lib/Middleware/OnlyLoggedInMiddleware.php @@ -22,8 +22,10 @@ namespace OCA\User_SAML\Middleware; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Middleware; use OCP\AppFramework\Utility\IControllerMethodReflector; +use OCP\IURLGenerator; use OCP\IUserSession; /** @@ -37,15 +39,21 @@ class OnlyLoggedInMiddleware extends Middleware { private $reflector; /** @var IUserSession */ private $userSession; + /** @var IURLGenerator */ + private $urlGenerator; /** * @param IControllerMethodReflector $reflector * @param IUserSession $userSession */ - public function __construct(IControllerMethodReflector $reflector, - IUserSession $userSession) { + public function __construct( + IControllerMethodReflector $reflector, + IUserSession $userSession, + IURLGenerator $urlGenerator + ) { $this->reflector = $reflector; $this->userSession = $userSession; + $this->urlGenerator = $urlGenerator; } /** @@ -63,12 +71,12 @@ class OnlyLoggedInMiddleware extends Middleware { * @param \OCP\AppFramework\Controller $controller * @param string $methodName * @param \Exception $exception - * @return JSONResponse + * @return RedirectResponse * @throws \Exception */ public function afterException($controller, $methodName, \Exception $exception) { if($exception->getMessage() === 'User is already logged-in') { - return new JSONResponse('User is already logged-in', 403); + return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/')); } throw $exception; |