Browse Source

Cleanup the Controllers

Redirect properly to the default page when reaching the room url
Add an option to set the chat page as the main one
pull/856/head
Timothée Jaussoin 6 years ago
parent
commit
abfca070e9
  1. 1
      CHANGELOG.md
  2. 6
      app/User.php
  3. 5
      app/controllers/AboutController.php
  4. 5
      app/controllers/AccountController.php
  5. 5
      app/controllers/AccountnextController.php
  6. 5
      app/controllers/AdminController.php
  7. 5
      app/controllers/AdminloginController.php
  8. 1
      app/controllers/BlogController.php
  9. 5
      app/controllers/DisconnectController.php
  10. 5
      app/controllers/FeedController.php
  11. 5
      app/controllers/InfosController.php
  12. 7
      app/controllers/LoginController.php
  13. 5
      app/controllers/ManifestController.php
  14. 4
      app/controllers/NewsController.php
  15. 1
      app/controllers/NodeController.php
  16. 5
      app/controllers/NotfoundController.php
  17. 4
      app/controllers/PictureController.php
  18. 4
      app/controllers/PopuptestController.php
  19. 5
      app/controllers/SystemController.php
  20. 5
      app/controllers/TagController.php
  21. 4
      app/controllers/VisioController.php
  22. 22
      app/widgets/Config/_config_form.tpl
  23. 2
      app/widgets/Config/locales.ini
  24. 21
      database/migrations/20190722083613_add_chatmain_to_users_table.php
  25. 8
      src/Movim/Controller/Base.php
  26. 8
      src/Movim/Controller/Front.php
  27. 24
      src/Movim/Route.php

1
CHANGELOG.md

@ -18,6 +18,7 @@ v0.15 – Donati (trunk)
* Comment and remove SQLite support in the project
* Using XEP-0372: References allow Movim users to share articles in the chats and chatrooms
* Display errors when the Pubsub nodes config are not saved
* Add an option to make the Chat page the main one
v0.14.1
---------------------------

6
app/User.php

@ -8,7 +8,7 @@ use App\Contact;
class User extends Model
{
protected $fillable = ['id', 'language', 'nightmode', 'nsfw', 'cssurl', 'nickname'];
protected $fillable = ['id', 'language', 'nightmode', 'chatmain', 'nsfw', 'cssurl', 'nickname'];
public $with = ['session', 'capability'];
public $incrementing = false;
private static $me = null;
@ -115,6 +115,10 @@ class User extends Model
$this->nsfw = $config['nsfw'];
}
if (isset($config['chatmain'])) {
$this->chatmain = $config['chatmain'];
}
if (isset($config['nightmode'])) {
$this->nightmode = $config['nightmode'];
}

5
app/controllers/AboutController.php

@ -4,11 +4,6 @@ use Movim\Controller\Base;
class AboutController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.about'));

5
app/controllers/AccountController.php

@ -3,11 +3,6 @@ use Movim\Controller\Base;
class AccountController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
requestAPI('disconnect', 2, ['sid' => SESSION_ID]);

5
app/controllers/AccountnextController.php

@ -4,11 +4,6 @@ use Movim\Controller\Base;
class AccountnextController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.account_creation'));

5
app/controllers/AdminController.php

@ -4,11 +4,6 @@ use Movim\Controller\Base;
class AdminController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
session_start();

5
app/controllers/AdminloginController.php

@ -5,11 +5,6 @@ use App\Configuration;
class AdminloginController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.administration'));

1
app/controllers/BlogController.php

@ -6,7 +6,6 @@ class BlogController extends Base
{
public function load()
{
$this->session_only = false;
$this->public = true;
}

5
app/controllers/DisconnectController.php

@ -6,11 +6,6 @@ use Movim\Session;
class DisconnectController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
// Just in case

5
app/controllers/FeedController.php

@ -6,11 +6,6 @@ class FeedController extends Base
{
public function load()
{
$this->session_only = false;
$this->raw = true;
}
public function dispatch()
{
}
}

5
app/controllers/InfosController.php

@ -7,11 +7,6 @@ class InfosController extends Base
public function load()
{
header('Content-type: application/json');
$this->session_only = false;
$this->raw = true;
}
public function dispatch()
{
}
}

7
app/controllers/LoginController.php

@ -5,11 +5,6 @@ use Respect\Validation\Validator;
class LoginController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.login'));
@ -20,7 +15,7 @@ class LoginController extends Base
$invitation = \App\Invite::find($this->fetchGet('i'));
$this->redirect('chat', [$invitation->resource, 'room']);
} else {
$this->redirect('root');
$this->redirect('main');
}
}
}

5
app/controllers/ManifestController.php

@ -7,11 +7,6 @@ class ManifestController extends Base
public function load()
{
header('Content-type: application/json');
$this->session_only = false;
$this->raw = true;
}
public function dispatch()
{
}
}

4
app/controllers/NewsController.php

@ -17,9 +17,5 @@ class NewsController extends Base
if (!\App\User::me()->hasPubsub()) {
$this->redirect('contact');
}
if (!\App\User::me()->isLogged()) {
$this->redirect('login');
}
}
}

1
app/controllers/NodeController.php

@ -6,7 +6,6 @@ class NodeController extends Base
{
public function load()
{
$this->session_only = false;
$this->public = true;
}

5
app/controllers/NotfoundController.php

@ -4,11 +4,6 @@ use Movim\Controller\Base;
class NotfoundController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.not_found'));

4
app/controllers/PictureController.php

@ -9,8 +9,4 @@ class PictureController extends Base
$this->session_only = true;
$this->raw = true;
}
public function dispatch()
{
}
}

4
app/controllers/PopuptestController.php

@ -9,8 +9,4 @@ class PopuptestController extends Base
$this->unique = true;
$this->session_only = true;
}
public function dispatch()
{
}
}

5
app/controllers/SystemController.php

@ -5,11 +5,6 @@ class SystemController extends Base
{
public function load()
{
$this->session_only = false;
$this->raw = true;
}
public function dispatch()
{
}
}

5
app/controllers/TagController.php

@ -4,11 +4,6 @@ use Movim\Controller\Base;
class TagController extends Base
{
public function load()
{
$this->session_only = false;
}
public function dispatch()
{
$this->page->setTitle(__('page.tag'));

4
app/controllers/VisioController.php

@ -9,8 +9,4 @@ class VisioController extends Base
$this->unique = true;
$this->session_only = true;
}
public function dispatch()
{
}
}

22
app/widgets/Config/_config_form.tpl

@ -27,6 +27,28 @@
<label for="language">{$c->__('config.language')}</label>
</div>
<div class="block">
<ul class="list thick">
<li>
<span class="primary icon gray">
<i class="material-icons">forum</i>
</span>
<span class="control">
<div class="checkbox">
<input
{if="$conf->chatmain"}checked{/if}
type="checkbox"
id="chatmain"
name="chatmain"/>
<label for="chatmain"></label>
</div>
</span>
<p class="line">{$c->__('config.chatmain')}</p>
<p class="line">{$c->__('config.chatmain_text')}</p>
</li>
</ul>
</div>
<div class="block">
<ul class="list thick">
<li>

2
app/widgets/Config/locales.ini

@ -12,6 +12,8 @@ nsfw = Display adult content
nsfw_text = Will allow you to read the posts tagged with the #nsfw tag
night_mode = Night Mode
night_mode_text = Use dark colors to rest your eyes
chatmain = Main chat page
chatmain_text = Make the chat page as the default one
mam = Archiving preferences
mam_text = Server-side archiving preferences
mam_always = Always

21
database/migrations/20190722083613_add_chatmain_to_users_table.php

@ -0,0 +1,21 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddChatMainToUsersTable extends Migration
{
public function up()
{
$this->schema->table('users', function (Blueprint $table) {
$table->boolean('chatmain')->default(false);
});
}
public function down()
{
$this->schema->table('users', function (Blueprint $table) {
$table->dropColumn('chatmain');
});
}
}

8
src/Movim/Controller/Base.php

@ -109,4 +109,12 @@ class Base
echo $this->page->build('page', $this->public);
}
}
public function load()
{
}
public function dispatch()
{
}
}

8
src/Movim/Controller/Front.php

@ -11,7 +11,13 @@ class Front extends Base
public function handle()
{
$r = new Route;
$this->runRequest($r->find());
$page = $r->find();
if ($page === null) {
$this->redirect($r->getRedirect());
} else {
$this->runRequest($page);
}
}
public function loadController($request)

24
src/Movim/Route.php

@ -3,11 +3,13 @@
namespace Movim;
use Movim\Controller\Base;
use App\User;
class Route extends Base
{
public $_routes;
private $_page;
private $_redirect;
public function __construct()
{
@ -72,24 +74,30 @@ class Route extends Base
}
if (empty($this->_page) || $this->_page == 'main') {
$this->_page = 'news';
}
$this->_page = null;
$user = User::me();
if (!isset($this->_routes[$this->_page])) {
$this->_page = 'notfound';
$this->_redirect = ($user->isLogged() && $user->chatmain)
? 'chat'
: 'news';
} else if (!isset($this->_routes[$this->_page])) {
$this->_page = null;
$this->_redirect = 'notfound';
}
return $this->_page;
}
public function getRedirect()
{
return $this->_redirect;
}
public static function urlize($page, $params = false, $get = [], $tab = false)
{
$routes = (new Route)->_routes;
if ($page === 'root') {
return BASE_URI;
}
if (isset($routes[$page])) {
$uri = BASE_URI . '?'. $page;

Loading…
Cancel
Save