Relocation of some code to simplify ACL later

This commit is contained in:
Christian Wolf 2019-06-14 14:53:37 +02:00
parent 7411516c5b
commit 52a5ebea3a
4 changed files with 52 additions and 5 deletions

View File

@ -7,6 +7,9 @@ use Joomla\CMS\Factory;
defined('_JEXEC') or die; defined('_JEXEC') or die;
JLoader::discover('Clubs', JPATH_ROOT . '/administrator/components/com_clubs/mymodels'); JLoader::discover('Clubs', JPATH_ROOT . '/administrator/components/com_clubs/mymodels');
JLoader::register("ClubsHelperAuth", JPATH_ROOT . "/components/com_clubs/helpers/auth.php");
JLoader::registerPrefix('AbstractClubs', JPATH_ROOT . '/administrator/components/com_clubs/abstract'); JLoader::registerPrefix('AbstractClubs', JPATH_ROOT . '/administrator/components/com_clubs/abstract');
JLoader::registerPrefix('AbstractCommonClubs', JPATH_ROOT . '/administrator/components/com_clubs/common/abstract'); JLoader::registerPrefix('AbstractCommonClubs', JPATH_ROOT . '/administrator/components/com_clubs/common/abstract');

View File

@ -1,6 +1,7 @@
<?php <?php
use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
@ -10,11 +11,50 @@ class ClubsController extends BaseController
public function display($cachable = false, $params = array()) public function display($cachable = false, $params = array())
{ {
parent::display($cachable, $params); $auth = new ClubsHelperAuth();
$app = Factory::getApplication();
$view = $app->input->getCmd('view');
// Most of the pages can only be viewd as a logged-in user
if($auth->isValidUserLoggedIn())
{
if($this->isUrlAllowed($view))
{
parent::display($cachable, $params);
return;
}
else
{
// User is not allowed to see the site, give useful information
}
}
else
{
if($view === 'login' || $view === 'publicclubs')
{
parent::display($cachable, $params);
return;
}
else
{
// User needs to login in order to see the site
$this->redirectToLogin();
}
}
$this->redirectToLogin();
} }
public function foo() private function redirectToLogin()
{ {
echo "dsfh"; // XXX Attach URL to forward later
$this->setRedirect('index.php?opion=com_clubs&view=login');
}
private function isUrlAllowed($view)
{
// FIXME Insert ACLs checking here
return true;
} }
} }

View File

@ -6,8 +6,6 @@ use Joomla\CMS\Factory;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
JLoader::register("ClubsHelperAuth", JPATH_ROOT . "/components/com_clubs/helpers/auth.php");
class ClubsControllerLogin extends BaseController class ClubsControllerLogin extends BaseController
{ {
public function login() public function login()

View File

@ -9,6 +9,12 @@ defined('_JEXEC') or die;
class ClubsHelperAuth class ClubsHelperAuth
{ {
public function isValidUserLoggedIn()
{
// FIXME
return true;
}
public function checkUser($user, $pwd) public function checkUser($user, $pwd)
{ {
$userModel = BaseDatabaseModel::getInstance("user", "ClubsModel"); $userModel = BaseDatabaseModel::getInstance("user", "ClubsModel");