Commit 93892ba1 authored by Tino Goratsch's avatar Tino Goratsch

- renamed the "Auth" class to "User" + method renaming

- use the Filesystem::scandir() method some more
parent 4fcaed82
......@@ -11,9 +11,9 @@ use ACP3\Modules\ACP3\Permissions;
class ACL
{
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \ACP3\Core\Modules
*/
......@@ -46,19 +46,19 @@ class ACL
protected $resources = [];
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Modules\ACP3\Permissions\Model $permissionsModel
* @param \ACP3\Modules\ACP3\Permissions\Cache $permissionsCache
*/
public function __construct(
Auth $auth,
User $user,
Modules $modules,
Permissions\Model $permissionsModel,
Permissions\Cache $permissionsCache
)
{
$this->auth = $auth;
$this->user = $user;
$this->modules = $modules;
$this->permissionsModel = $permissionsModel;
$this->permissionsCache = $permissionsCache;
......@@ -70,7 +70,7 @@ class ACL
protected function getPrivileges()
{
if ($this->privileges === []) {
$this->privileges = $this->getRules($this->getUserRoleIds($this->auth->getUserId()));
$this->privileges = $this->getRules($this->getUserRoleIds($this->user->getUserId()));
}
return $this->privileges;
......@@ -173,7 +173,7 @@ class ACL
*/
public function userHasRole($roleId)
{
return in_array($roleId, $this->getUserRoleIds($this->auth->getUserId()));
return in_array($roleId, $this->getUserRoleIds($this->user->getUserId()));
}
/**
......@@ -204,7 +204,7 @@ class ACL
} elseif (isset($this->getResources()[$area][$resource])) {
$module = $resourceArray[1];
$key = $this->getResources()[$area][$resource]['key'];
return $this->userHasPrivilege($module, $key) === true || $this->auth->isSuperUser() === true;
return $this->userHasPrivilege($module, $key) === true || $this->user->isSuperUser() === true;
}
return false;
......
......@@ -163,7 +163,7 @@ class Application extends AbstractApplication
// Load system settings
$this->systemSettings = $this->container->get('core.config')->getSettings('system');
$this->_setThemeConstants();
$this->container->get('core.auth')->authenticate();
$this->container->get('core.user')->authenticate();
$this->container->get('core.view')->setRenderer('smarty');
/** @var \ACP3\Core\Http\Request $request */
......@@ -178,8 +178,7 @@ class Application extends AbstractApplication
$redirect = $this->container->get('core.redirect');
try {
$frontController = new FrontController($this->container);
$frontController->dispatch();
(new FrontController($this->container))->dispatch();
} catch (Exceptions\ResultNotExists $e) {
if ($e->getMessage()) {
ACP3Logger::error('404', $e);
......@@ -243,9 +242,9 @@ class Application extends AbstractApplication
}
/**
* @param $containerConfigCache
* @param \Symfony\Component\Config\ConfigCache $containerConfigCache
*/
protected function dumpContainer($containerConfigCache)
protected function dumpContainer(ConfigCache $containerConfigCache)
{
$containerBuilder = new ContainerBuilder();
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__));
......
......@@ -11,9 +11,6 @@ use Symfony\Component\DependencyInjection\Container;
class Breadcrumb
{
/**
* Enthält alle Schritte der Brotkrümelspur,
* welche von den Modulen festgelegt werden
*
* @var array
*/
protected $steps = [];
......@@ -28,8 +25,6 @@ class Breadcrumb
];
/**
* Enthält die gecachete Brotkrümelspur
*
* @var array
*/
protected $breadcrumbCache = [];
......@@ -77,13 +72,6 @@ class Breadcrumb
$this->config = $config;
}
/**
* Initializes and pre populates the breadcrumb
*/
public function prePopulate()
{
}
/**
*
* @param string $value
......
......@@ -35,12 +35,12 @@ class Date
protected $config;
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Config $config
*/
public function __construct(
Auth $auth,
User $user,
Lang $lang,
Config $config
)
......@@ -48,7 +48,7 @@ class Date
$this->lang = $lang;
$this->config = $config;
$this->_setFormatAndTimeZone($auth->getUserInfo());
$this->_setFormatAndTimeZone($user->getUserInfo());
}
/**
......
......@@ -10,9 +10,9 @@ use ACP3\Core\Lang\Cache as LanguageCache;
class Lang
{
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \ACP3\Core\Lang\Cache
*/
......@@ -41,17 +41,17 @@ class Lang
protected $buffer = [];
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang\Cache $cache
* @param \ACP3\Core\Config $config
*/
public function __construct(
Auth $auth,
User $user,
LanguageCache $cache,
Config $config
)
{
$this->auth = $auth;
$this->user = $user;
$this->cache = $cache;
$this->config = $config;
}
......@@ -76,7 +76,7 @@ class Lang
public function getLanguage()
{
if ($this->lang === '') {
$lang = $this->auth->getUserLanguage();
$lang = $this->user->getLanguage();
$this->lang = self::languagePackExists($lang) === true ? $lang : $this->config->getSettings('system')['lang'];
}
......
......@@ -36,7 +36,7 @@ abstract class AdminController extends Core\Modules\FrontendController
*/
public function preDispatch()
{
if ($this->auth->isUser() === false) {
if ($this->user->isAuthenticated() === false) {
throw new Core\Exceptions\UnauthorizedAccess();
}
......
......@@ -16,9 +16,9 @@ abstract class Controller implements ControllerInterface
*/
protected $acl;
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
......@@ -76,7 +76,7 @@ abstract class Controller implements ControllerInterface
public function __construct(Controller\Context $context)
{
$this->acl = $context->getACL();
$this->auth = $context->getAuth();
$this->user = $context->getUser();
$this->lang = $context->getLang();
$this->request = $context->getRequest();
$this->router = $context->getRouter();
......
......@@ -2,7 +2,7 @@
namespace ACP3\Core\Modules\Controller;
use ACP3\Core\ACL;
use ACP3\Core\Auth;
use ACP3\Core\User;
use ACP3\Core\Config;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Lang;
......@@ -21,9 +21,9 @@ class Context
*/
protected $acl;
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \ACP3\Core\Lang
*/
......@@ -51,7 +51,7 @@ class Context
/**
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Core\Http\RequestInterface $request
......@@ -61,7 +61,7 @@ class Context
*/
public function __construct(
ACL $acl,
Auth $auth,
User $user,
Lang $lang,
Modules $modules,
RequestInterface $request,
......@@ -71,7 +71,7 @@ class Context
)
{
$this->acl = $acl;
$this->auth = $auth;
$this->user = $user;
$this->lang = $lang;
$this->modules = $modules;
$this->request = $request;
......@@ -89,11 +89,11 @@ class Context
}
/**
* @return \ACP3\Core\Auth
* @return \ACP3\Core\User
*/
public function getAuth()
public function getUser()
{
return $this->auth;
return $this->user;
}
/**
......
......@@ -43,7 +43,7 @@ class FrontendContext extends Core\Modules\Controller\Context
{
parent::__construct(
$context->getACL(),
$context->getAuth(),
$context->getUser(),
$context->getLang(),
$context->getModules(),
$context->getRequest(),
......
......@@ -65,12 +65,9 @@ abstract class FrontendController extends Core\Modules\Controller
// Get the current resultset position
if (!defined('POS')) {
define('POS', (int)$this->request->getParameters()->get('page') >= 1 ? (int)($this->request->getParameters()->get('page') - 1) * $this->auth->entries : 0);
define('POS', (int)$this->request->getParameters()->get('page') >= 1 ? (int)($this->request->getParameters()->get('page') - 1) * $this->user->getEntriesPerPage() : 0);
}
// Initialize the breadcrumb
$this->breadcrumb->prePopulate();
$this->view->assign('PHP_SELF', PHP_SELF);
$this->view->assign('REQUEST_URI', $this->request->getServer()->get('REQUEST_URI'));
$this->view->assign('ROOT_DIR', ROOT_DIR);
......
......@@ -11,9 +11,9 @@ use ACP3\Core\Validator\Rules\Misc;
class Pagination
{
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \ACP3\Core\Breadcrumb
*/
......@@ -80,7 +80,7 @@ class Pagination
private $pagination = [];
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Breadcrumb $breadcrumb
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\SEO $seo
......@@ -90,7 +90,7 @@ class Pagination
* @param \ACP3\Core\Validator\Rules\Misc $miscValidator
*/
public function __construct(
Auth $auth,
User $user,
Breadcrumb $breadcrumb,
Lang $lang,
SEO $seo,
......@@ -99,7 +99,7 @@ class Pagination
View $view,
Misc $miscValidator)
{
$this->auth = $auth;
$this->user = $user;
$this->breadcrumb = $breadcrumb;
$this->lang = $lang;
$this->seo = $seo;
......@@ -108,7 +108,7 @@ class Pagination
$this->view = $view;
$this->miscValidator = $miscValidator;
$this->resultsPerPage = $auth->entries;
$this->resultsPerPage = $user->getEntriesPerPage();
}
/**
......
......@@ -7,50 +7,32 @@ use ACP3\Core\Http\RequestInterface;
use ACP3\Modules\ACP3\Users;
/**
* Class Auth
* Class User
* @package ACP3\Core
*/
class Auth
class User
{
/**
* Name des Authentifizierungscookies
*/
const AUTH_NAME = 'ACP3_AUTH';
/**
* Length of the password salt
*/
const SALT_LENGTH = 16;
/**
* Lifetime of the remember me cookie
*/
const REMEMBER_ME_COOKIE_LIFETIME = 31104000;
/**
* Anzuzeigende Datensätze pro Seite
*
* @var integer
*/
public $entries = '';
public $entriesPerPage = 0;
/**
* Standardsprache des Benutzers
*
* @var string
*/
public $language = '';
protected $language = '';
/**
* Eingeloggter Benutzer oder nicht
*
* @var boolean
*/
protected $isUser = false;
protected $isAuthenticated = false;
/**
* ID des Benutzers
*
* @var integer
*/
protected $userId = 0;
/**
* Super User oder nicht
*
* @var boolean
*/
protected $superUser = false;
......@@ -117,7 +99,7 @@ class Auth
} else { // Guest user
$settings = $this->config->getSettings('system');
$this->entries = $settings['entries'];
$this->entriesPerPage = $settings['entries'];
$this->language = $settings['lang'];
}
}
......@@ -180,7 +162,7 @@ class Auth
*/
public function getUserInfo($userId = 0)
{
if (empty($userId) && $this->isUser() === true) {
if (empty($userId) && $this->isAuthenticated() === true) {
$userId = $this->getUserId();
}
......@@ -203,9 +185,9 @@ class Auth
*
* @return boolean
*/
public function isUser()
public function isAuthenticated()
{
return $this->isUser === true && $this->getUserId() !== 0;
return $this->isAuthenticated === true && $this->getUserId() !== 0;
}
/**
......@@ -222,11 +204,19 @@ class Auth
*
* @return string
*/
public function getUserLanguage()
public function getLanguage()
{
return $this->language;
}
/**
* @return int
*/
public function getEntriesPerPage()
{
return $this->entriesPerPage;
}
/**
* Gibt aus, ob der aktuell eingeloggte Benutzer der Super User ist, oder nicht
*
......@@ -294,8 +284,8 @@ class Auth
$this->sessionHandler->set(self::AUTH_NAME, [
'id' => $userData['id'],
'super_user' => (bool)$userData['super_user'],
'entries' => $this->setUserEntriesPerPage($userData),
'language' => $this->setUserLanguage($userData)
'entries' => $this->setEntriesPerPage($userData),
'language' => $this->setLanguage($userData)
]);
}
......@@ -316,10 +306,10 @@ class Auth
*/
protected function populateUserData(array $data)
{
$this->isUser = true;
$this->isAuthenticated = true;
$this->userId = (int)$data['id'];
$this->superUser = (bool)$data['super_user'];
$this->entries = (int)$data['entries'];
$this->entriesPerPage = (int)$data['entries'];
$this->language = $data['language'];
}
......@@ -339,7 +329,7 @@ class Auth
*
* @return int
*/
private function setUserEntriesPerPage(array $user)
private function setEntriesPerPage(array $user)
{
$userSettings = $this->config->getSettings('users');
$systemSettings = $this->config->getSettings('system');
......@@ -356,7 +346,7 @@ class Auth
*
* @return string
*/
private function setUserLanguage(array $user)
private function setLanguage(array $user)
{
$userSettings = $this->config->getSettings('users');
$systemSettings = $this->config->getSettings('system');
......
services:
core.context:
class: ACP3\Core\Modules\Controller\Context
arguments: ['@core.acl', '@core.auth', '@core.lang', '@core.modules', '@core.request', '@core.router', '@core.view', '@core.config']
arguments: ['@core.acl', '@core.user', '@core.lang', '@core.modules', '@core.request', '@core.router', '@core.view', '@core.config']
public: false
core.context.admin:
......
......@@ -15,11 +15,7 @@ imports:
services:
core.acl:
class: ACP3\Core\ACL
arguments: ['@core.auth', '@core.modules', '@permissions.model', '@permissions.cache']
core.auth:
class: ACP3\Core\Auth
arguments: [@core.request, '@core.session', '@core.helpers.secure', '@core.config', '@users.model']
arguments: ['@core.user', '@core.modules', '@permissions.model', '@permissions.cache']
core.breadcrumb:
class: ACP3\Core\Breadcrumb
......@@ -35,7 +31,7 @@ services:
core.date:
class: ACP3\Core\Date
arguments: ['@core.auth', '@core.lang', '@core.config']
arguments: ['@core.user', '@core.lang', '@core.config']
core.db:
class: ACP3\Core\DB
......@@ -46,7 +42,7 @@ services:
core.lang:
class: ACP3\Core\Lang
arguments: ['@core.auth', @core.lang.cache, '@core.config']
arguments: ['@core.user', @core.lang.cache, '@core.config']
core.lang.cache:
class: ACP3\Core\Lang\Cache
......@@ -58,7 +54,7 @@ services:
core.pagination:
class: ACP3\Core\Pagination
arguments: ['@core.auth', '@core.breadcrumb', '@core.lang', '@core.seo', '@core.request', '@core.router', '@core.view', '@core.validator.rules.misc']
arguments: ['@core.user', '@core.breadcrumb', '@core.lang', '@core.seo', '@core.request', '@core.router', '@core.view', '@core.validator.rules.misc']
core.redirect:
class: ACP3\Core\Redirect
......@@ -84,6 +80,10 @@ services:
class: ACP3\Core\SessionHandler
arguments: ['@core.db', @core.request]
core.user:
class: ACP3\Core\User
arguments: [@core.request, '@core.session', '@core.helpers.secure', '@core.config', '@users.model']
core.view:
class: ACP3\Core\View
calls:
......
......@@ -146,7 +146,7 @@ class Index extends Core\Modules\AdminController
'end' => $this->date->toSQL($formData['end']),
'title' => Core\Functions::strEncode($formData['title']),
'text' => Core\Functions::strEncode($formData['text'], true),
'user_id' => $this->auth->getUserId(),
'user_id' => $this->user->getUserId(),
];
$lastId = $this->articlesModel->insert($insertValues);
......@@ -261,7 +261,7 @@ class Index extends Core\Modules\AdminController
'end' => $this->date->toSQL($formData['end']),
'title' => Core\Functions::strEncode($formData['title']),
'text' => Core\Functions::strEncode($formData['text'], true),
'user_id' => $this->auth->getUserId(),
'user_id' => $this->user->getUserId(),
];
$bool = $this->articlesModel->update($updateValues, $id);
......@@ -295,7 +295,7 @@ class Index extends Core\Modules\AdminController
'sort_col' => $canDelete === true ? 2 : 1,
'sort_dir' => 'asc',
'hide_col_sort' => $canDelete === true ? 0 : '',
'records_per_page' => $this->auth->entries
'records_per_page' => $this->user->getEntriesPerPage()
];
$this->view->assign('datatable_config', $config);
$this->view->assign('articles', $articles);
......
......@@ -62,7 +62,7 @@ class Index extends Core\Modules\FrontendController
{
$time = $this->date->getCurrentDateTime();
$articles = $this->articlesModel->getAll($time, POS, $this->auth->entries);
$articles = $this->articlesModel->getAll($time, POS, $this->user->getEntriesPerPage());
$c_articles = count($articles);
if ($c_articles > 0) {
......
......@@ -10,9 +10,9 @@ use ACP3\Core;
class Helpers
{
/**
* @var \ACP3\Core\Auth
* @var \ACP3\Core\User
*/
protected $auth;
protected $user;
/**
* @var \ACP3\Core\Helpers\Secure
*/
......@@ -35,7 +35,7 @@ class Helpers
protected $view;
/**
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\User $user
* @param \ACP3\Core\Http\Request $request
* @param \ACP3\Core\Router $router
* @param \ACP3\Core\SessionHandler $sessionHandler
......@@ -43,7 +43,7 @@ class Helpers
* @param \ACP3\Core\Helpers\Secure $secureHelper
*/
public function __construct(
Core\Auth $auth,
Core\User $user,
Core\Http\Request $request,
Core\Router $router,
Core\SessionHandler $sessionHandler,
......@@ -51,7 +51,7 @@ class Helpers
Core\Helpers\Secure $secureHelper
)
{
$this->auth = $auth;
$this->user = $user;
$this->request = $request;
$this->router = $router;
$this->sessionHandler = $sessionHandler;
......@@ -72,7 +72,7 @@ class Helpers
public function captcha($captchaLength = 5, $id = 'captcha', $inputOnly = false, $path = '')
{
// Wenn man als User angemeldet ist, Captcha nicht anzeigen
if ($this->auth->isUser() === false) {
if ($this->user->isAuthenticated() === false) {
$path = sha1($this->router->route(empty($path) === true ? $this->request->getQuery() : $path));
$this->sessionHandler->set('captcha_' . $path, $this->secureHelper->salt($captchaLength));
......
......@@ -11,7 +11,7 @@ services:
captcha.helpers:
class: %captcha.helpers.fqdn%
arguments: ['@core.auth', '@core.request', '@core.router', @core.session, '@core.view', '@core.helpers.secure']
arguments: ['@core.user', '@core.request', '@core.router', @core.session, '@core.view', '@core.helpers.secure']
captcha.installer.schema:
class: %captcha.installer.schema.fqdn%
......
......@@ -221,7 +221,7 @@ class Index extends Core\Modules\AdminController
'sort_col' => $canDelete === true ? 1 : 0,
'sort_dir' => 'desc',
'hide_col_sort' => $canDelete === true ? 0 : '',
'records_per_page' => $this->auth->entries
'records_per_page' => $this->user->getEntriesPerPage()
];
$this->view->assign('datatable_config', $config);
for ($i = 0; $i < $c_categories; ++$i) {
......
......@@ -161,7 +161,7 @@ class Details extends Core\Modules\AdminController
'sort_col' => $canDelete === true ? 5 : 4,
'sort_dir' => 'asc',
'hide_col_sort' => $canDelete === true ? 0 : '',
'records_per_page' => $this->auth->entries
'records_per_page' => $this->user->getEntriesPerPage()
];
$this->view->assign('datatable_config', $config);
......
......@@ -83,7 +83,7 @@ class Index extends Core\Modules\AdminController
'sort_col' => $canDelete === true ? 1 : 0,
'sort_dir' => 'desc',
'hide_col_sort' => $canDelete === true ? 0 : '',
'records_per_page' => $this->auth->entries
'records_per_page' => $this->user->getEntriesPerPage()
];
$this->view->assign('datatable_config', $config);
......
......@@ -143,7 +143,7 @@ class Index extends Core\Modules\FrontendController
public function actionIndex()
{
// Auflistung der Kommentare
$comments = $this->commentsModel->getAllByModule($this->modules->getModuleId($this->module), $this->entryId, POS, $this->auth->entries);
$comments = $this->commentsModel->getAllByModule($this->modules->getModuleId($this->module), $this->entryId, POS, $this->user->getEntriesPerPage());
$c_comments = count($comments);
if ($c_comments > 0) {
......@@ -190,8 +190,8 @@ class Index extends Core\Modules\FrontendController
];
// Falls Benutzer eingeloggt ist, Formular schon teilweise ausfüllen
if ($this->auth->isUser() === true) {
$user = $this->auth->getUserInfo();
if ($this->user->isAuthenticated() === true) {
$user = $this->user->getUserInfo();
$disabled = ' readonly="readonly"';
$defaults['name'] = $user['nickname'];
$defaults['name_disabled'] = $disabled;
......@@ -225,7 +225,7 @@ class Index extends Core\Modules\FrontendController
'date' => $this->date->toSQL(),
'ip' => $ip,
'name' => Core\Functions::strEncode($formData['name']),
'user_id' => $this->auth->isUser() === true && $this->get('core.validator.rules.misc')->isNumber($this->auth->getUserId() === true) ? $this->auth->getUserId() : '',
'user_id' => $this->user->isAuthenticated() === true && $this->get('core.validator.rules.misc')->isNumber($this->user->getUserId() === true) ? $this->user->getUserId() : '',
'message' => Core\Functions::strEncode($formData['message']),
'module_id' => $this->modules->getModuleId($this->module),