Browse Source

Redirect the user properly if he tries to access ?post from an unauthenticated account

Code cleanup
pull/676/head
Timothée Jaussoin 8 years ago
parent
commit
455bbd64e8
  1. 1
      CHANGELOG.md
  2. 20
      app/controllers/PostController.php
  3. 17
      src/Movim/Controller/Base.php
  4. 1
      src/Movim/Route.php
  5. 8
      src/Movim/Widget/Base.php

1
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
---------------------------

20
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');
}
}
}
}

17
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';
}
}

1
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'],

8
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;

Loading…
Cancel
Save