From 455bbd64e8bbb952ad0633fcedc991c9868af9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Sun, 20 May 2018 16:47:11 +0200 Subject: [PATCH] Redirect the user properly if he tries to access ?post from an unauthenticated account Code cleanup --- CHANGELOG.md | 1 + app/controllers/PostController.php | 20 ++++++++++++++++++++ src/Movim/Controller/Base.php | 17 ++++++++--------- src/Movim/Route.php | 1 + src/Movim/Widget/Base.php | 8 +++----- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54f7e8b14..d09ff372e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ v0.14 (trunk) * Remove several dependencies (heyupdate/emoji, clue/buzz-react, ramsey/uuid) and fix the versions of some of them (react/zmq, rain/raintpl, react/http) * Improve handling of Emojis (by mirabilos) * Improve performances by using eager loading (for Chats, Posts and Contacts related widgets) + * Redirect the unauthenticated to the correct page when trying to access ?post v0.13 --------------------------- diff --git a/app/controllers/PostController.php b/app/controllers/PostController.php index 60ed5bca3..8ab1b7b8a 100644 --- a/app/controllers/PostController.php +++ b/app/controllers/PostController.php @@ -11,5 +11,25 @@ class PostController extends Base function dispatch() { $this->page->setTitle(__('page.post')); + + $user = new \App\User; + if (!$user->isLogged()) { + $post = App\Post::where([ + 'server' => $this->fetchGet('s'), + 'node' => $this->fetchGet('n'), + 'nodeid' => $this->fetchGet('i'), + 'open' => true + ])->first(); + + if ($post) { + if ($post->isMicroblog()) { + $this->redirect('blog', [$this->fetchGet('s'), $this->fetchGet('i')]); + } else { + $this->redirect('node', [$this->fetchGet('s'),$this->fetchGet('n'), $this->fetchGet('i')]); + } + } else { + $this->redirect('notfound'); + } + } } } diff --git a/src/Movim/Controller/Base.php b/src/Movim/Controller/Base.php index 44f5a125a..dbb9bd8b3 100644 --- a/src/Movim/Controller/Base.php +++ b/src/Movim/Controller/Base.php @@ -17,7 +17,7 @@ class Base function __construct() { - $this->page = new Builder(); + $this->page = new Builder; } /** @@ -30,9 +30,9 @@ class Base { if (isset($_GET[$name])) { return htmlentities($_GET[$name]); - } else { - return false; } + + return false; } /** @@ -45,17 +45,16 @@ class Base { if (isset($_POST[$name])) { return htmlentities($_POST[$name]); - } else { - return false; } + + return false; } function checkSession() { - if ($this->session_only) { - if (!(new \App\User)->isLogged()) { - $this->name = 'login'; - } + if ($this->session_only + && !(new \App\User)->isLogged()) { + $this->name = 'login'; } } diff --git a/src/Movim/Route.php b/src/Movim/Route.php index 827e4bdf1..7ed86a128 100644 --- a/src/Movim/Route.php +++ b/src/Movim/Route.php @@ -28,6 +28,7 @@ class Route extends Base 'infos' => false, 'login' => ['i'], 'main' => false, + 'notfound' => false, 'node' => ['s', 'n', 'i'], 'news' => ['s', 'n', 'i'], 'post' => ['s', 'n', 'i'], diff --git a/src/Movim/Widget/Base.php b/src/Movim/Widget/Base.php index 42c52bf80..fee3549b3 100644 --- a/src/Movim/Widget/Base.php +++ b/src/Movim/Widget/Base.php @@ -187,11 +187,9 @@ class Base */ protected function respath($file, $fspath = false, $parent = false, $notime = false) { - if ($parent == false) { - $folder = get_class($this); - } else { - $folder = get_parent_class($this); - } + $folder = ($parent == false) + ? get_class($this) + : get_parent_class($this); $path = 'app/widgets/' . $folder . '/' . $file;