replace global var $needAuth with function need_auth()

This commit is contained in:
Max Pozdeev 2020-09-08 14:37:29 +03:00
parent d99c85c4eb
commit bd698949a5
6 changed files with 17 additions and 13 deletions

View file

@ -15,7 +15,7 @@ $db = DBConnection::instance();
if(isset($_GET['loadLists']))
{
if($needAuth && !is_logged()) $sqlWhere = 'WHERE published=1';
if (need_auth() && !is_logged()) $sqlWhere = 'WHERE published=1';
else $sqlWhere = '';
$t = array();
$t['total'] = 0;
@ -297,7 +297,7 @@ elseif(isset($_GET['changeOrder']))
elseif(isset($_POST['login']))
{
$t = array('logged' => 0);
if(!$needAuth) {
if (!need_auth()) {
$t['disabled'] = 1;
jsonExit($t);
}

View file

@ -14,7 +14,7 @@ $lang = Lang::instance();
$listId = (int)_get('list');
$listData = $db->sqa("SELECT * FROM {$db->prefix}lists WHERE id=$listId");
if($needAuth && (!$listData || !$listData['published'])) {
if (need_auth() && (!$listData || !$listData['published'])) {
die("Access denied!<br> List is not published.");
}
if(!$listData) {

View file

@ -63,8 +63,7 @@ Lang::loadLang(Config::get('lang'));
$_mttinfo = array();
$needAuth = (Config::get('password') != '') ? 1 : 0;
if($needAuth && !isset($dontStartSession))
if (need_auth() && !isset($dontStartSession))
{
if(Config::get('session') == 'files')
{
@ -81,16 +80,21 @@ if($needAuth && !isset($dontStartSession))
session_start();
}
function need_auth()
{
return (Config::get('password') != '') ? 1 : 0;
}
function is_logged()
{
if(!isset($_SESSION['logged']) || !$_SESSION['logged']) return false;
return true;
if ( !need_auth() ) return true;
if ( isset($_SESSION['logged']) && $_SESSION['logged'] ) return true;
return false;
}
function is_readonly()
{
$needAuth = (Config::get('password') != '') ? 1 : 0;
if($needAuth && !is_logged()) return true;
if (need_auth() && !is_logged()) return true;
return false;
}

View file

@ -10,7 +10,7 @@ require_once('./init.php');
$lang = Lang::instance();
if($needAuth && !is_logged())
if (need_auth() && !is_logged())
{
die("Access denied!<br/> Disable password protection or Log in.");
}

View file

@ -27,7 +27,7 @@ if(!isset($config['db']))
if($config['db'] != '')
{
require_once('./init.php');
if($needAuth && !is_logged())
if (need_auth() && !is_logged())
{
die("Access denied!<br> Disable password protection or Log in.");
}

View file

@ -29,8 +29,8 @@ $().ready(function(){
lang: <?php echo Lang::instance()->makeJS() ?>,
mttUrl: "<?php mttinfo('mtt_url'); ?>",
db: mytinytodoStorageAjax,
needAuth: <?php echo $needAuth ? "true" : "false"; ?>,
isLogged: <?php echo ($needAuth && is_logged()) ? "true" : "false"; ?>,
needAuth: <?php echo need_auth() ? "true" : "false"; ?>,
isLogged: <?php echo (need_auth() && is_logged()) ? "true" : "false"; ?>,
showdate: <?php echo (Config::get('showdate') && !Config::get('mobile')) ? "true" : "false"; ?>,
singletab: <?php echo (isset($_GET['singletab']) || Config::get('mobile')) ? "true" : "false"; ?>,
duedatepickerformat: "<?php echo htmlspecialchars(Config::get('dateformat2')); ?>",