diff --git a/libraries/Template.php b/libraries/Template.php index a8493a8..69b1ef1 100644 --- a/libraries/Template.php +++ b/libraries/Template.php @@ -99,7 +99,11 @@ class Template })); // Add config function - self::$engine->addFunction(new Twig_SimpleFunction('config', function ($name) { + self::$engine->addFunction(new Twig_SimpleFunction('config', function ($name, $local = false) { + if ($local) { + $name = explode('.', $name); + return Config::local($name[0], $name[1]); + } return Config::get($name); })); diff --git a/libraries/User.php b/libraries/User.php index 79ea784..4e51a83 100644 --- a/libraries/User.php +++ b/libraries/User.php @@ -425,6 +425,16 @@ class User return $this->lastOnline > (time() - Config::get('max_online_time')); } + /** + * Runs some checks to see if this user is activated. + * + * @return bool Are they activated? + */ + public function isActive() + { + return $this->id !== 0 && !$this->permission(Site::DEACTIVATED); + } + /** * Get a few forum statistics. * diff --git a/routes.php b/routes.php index 9ae695d..30b192e 100644 --- a/routes.php +++ b/routes.php @@ -8,7 +8,7 @@ namespace Sakura; // Check if logged out Router::filter('logoutCheck', function () { - if (ActiveUser::$user->id !== 0) { + if (ActiveUser::$user->isActive()) { $message = "You must be logged out to do that!"; Template::vars(['page' => compact('message')]); @@ -19,8 +19,7 @@ Router::filter('logoutCheck', function () { // Check if logged in Router::filter('loginCheck', function () { - if (ActiveUser::$user->id === 0 - || ActiveUser::$user->permission(Perms\Site::DEACTIVATED)) { + if (!ActiveUser::$user->isActive()) { $message = "You must be logged in to do that!"; Template::vars(['page' => compact('message')]); diff --git a/sakura.php b/sakura.php index 1871838..3f199b1 100644 --- a/sakura.php +++ b/sakura.php @@ -102,20 +102,11 @@ if (!defined('SAKURA_NO_TPL')) { // Set base page rendering data Template::vars([ 'sakura' => [ - 'versionInfo' => [ - 'version' => SAKURA_VERSION, - ], - - 'dev' => [ - 'showChangelog' => Config::local('dev', 'show_changelog'), - ], - 'currentPage' => $_SERVER['REQUEST_URI'] ?? null, 'referrer' => $_SERVER['HTTP_REFERER'] ?? null, ], 'session' => array_merge([ - 'checkLogin' => ActiveUser::$user->id && !ActiveUser::$user->permission(Perms\Site::DEACTIVATED), 'sessionId' => ActiveUser::$session->sessionId, ], $_SESSION), diff --git a/templates/misaki/global/master.twig b/templates/misaki/global/master.twig index e1805c9..c3739d5 100644 --- a/templates/misaki/global/master.twig +++ b/templates/misaki/global/master.twig @@ -55,7 +55,7 @@ "minUserLen": {{ config('username_min_length') }}, "maxUserLen": {{ config('username_max_length') }}, "minPwdEntropy": {{ config('min_entropy') }}, - "checkLogin": {% if session.checkLogin %}true{% else %}false{% endif %} + "checkLogin": {% if user.isActive %}true{% else %}false{% endif %} }; @@ -92,17 +92,17 @@ diff --git a/templates/misaki/main/profile.twig b/templates/misaki/main/profile.twig index 130288e..61e1dfe 100644 --- a/templates/misaki/main/profile.twig +++ b/templates/misaki/main/profile.twig @@ -87,7 +87,7 @@ {% endif %} - {% if session.checkLogin %} + {% if user.isActive %}