diff --git a/Conjuro/Conjuro.php b/Conjuro/Conjuro.php index 984b468..637dd56 100644 --- a/Conjuro/Conjuro.php +++ b/Conjuro/Conjuro.php @@ -36,7 +36,10 @@ $this->conf=$conf; //$this->loadControls(); } - + + ///////////////////////////////////////////////////// DATABASE TOOLS + //////////////////////////////////////////////////////////////////// + // Return data from database public function DBget($type,$key=""){ if ($key!="") @@ -125,9 +128,9 @@ } // Database - public function db(){ + private function db(){ if(!isset($this->db)) - $this->db=new DB($conf); + $this->db=new DB($this->conf); return $this->db; } @@ -137,6 +140,40 @@ return json_decode($json, true); } + /////////////////////////////////////////////////////////////// AUTH + //////////////////////////////////////////////////////////////////// + + /** + * Process the login information. + */ + public function login($usr,$pwd){ + $_SESSION['user']=null; // Reset previous login if any + $usr=strtolower($usr); + $user=$this->db()->selectOne('users',null,'where user=? and pass=sha1(?) and active=true','ss',$usr,$pwd); + $user['user']=strtolower($user['user']); + if ($user) + return $_SESSION['user']=$user; + // Check for bootstrap/recover users + foreach($this->conf['bootusers'] as $buser){ + if (strtolower($buser[0])==$usr && $buser[1]==$pwd) + return $_SESSION['user']=['user'=>strtolower($buser[0]),'name'=>$buser[0]]; + } + } + + /** + * Checks the current login information + */ + public function checkLogin(){ + if ($_SESSION['user']) // refresh user data + return $_SESSION['user']=$this->db()->selectOne('users',null,'where id=? and active=true','i',$_SESSION['user']['id']); + // Check for bootstrap/recover users + foreach($this->conf['bootusers'] as $buser){ + if (strtolower($buser[0])==$_SESSION['user']['user']) + return $_SESSION['user']=['user'=>strtolower($buser[0]),'name'=>$buser[0]]; + } + $_SESSION['user']=null; //Drop session if not found anymore + } + //////////////////////////////////////////////////// MODULE HANDLING //////////////////////////////////////////////////////////////////// diff --git a/content/controls/common.php b/content/controls/common.php index f2a3403..00f04b3 100644 --- a/content/controls/common.php +++ b/content/controls/common.php @@ -23,22 +23,32 @@ }, new class("form") extends Control{ protected function renderControl($meta,$data) { - $cols=$meta["columns"]; + $cols=$meta['columns']; c()->rhtml( 'form', - ['id'=>$meta['id'],'class'=>$meta['class']], + ['id'=>$meta['id'],'class'=>$meta['class'],'action'=>$meta['action'],'method'=>$meta['method']], fn()=>c()->rhtml( 'table', ['class'=>'form-body-table'], - function() use($meta,$data){ + function() use($meta,$data,$cols){ echo ''; $col=0; foreach($meta['childs'] as $child){ c()->renderContent($child,$data); - if($col++>=$cols){ + if(++$col>=$cols){ echo ''; } } + if ($meta['accept']||$meta['reset']){ //Buttons} + if ($col!=0) + echo ''; + echo ''; + if ($meta['accept']) + c()->rhtml('input',['type'=>'submit','value'=>$meta['accept']]); + if ($meta['reset']) + c()->rhtml('input',['type'=>'reset','value'=>$meta['reset']]); + echo ''; + } echo ''; } ) @@ -52,7 +62,25 @@ $vid=$meta["id"].'-value'; } c()->rhtml('td',['id'=>$lid,'class'=>'form-data-label '.$meta["class"]],fn()=>print(htmlentities($meta["label"]))); - c()->rhtml('td',['id'=>$vid,'class'=>'form-data-value '.$meta["class"]]); + c()->rhtml('td',['id'=>$vid,'class'=>'form-data-value '.$meta["class"]],function() use($meta,$data){ + $type=$meta['type']; + if (!$type) + $type='input'; + switch($type){ + case 'input': + echo c()->htmlopen('input',['id'=>$meta['id'],'name'=>$meta['id']]); + break; + case 'password': + echo c()->htmlopen('input',['id'=>$meta['id'],'name'=>$meta['id'],'type'=>'password']); + break; + } + }); + } + }, + new class("jump") extends Control{ + protected function renderControl($meta,$data) { + $ctt=$meta["height"]; + echo "
"; } } ]; diff --git a/content/fragment/layout-admin.php b/content/fragment/layout-admin.php index 9a5a3db..a8b04e9 100644 --- a/content/fragment/layout-admin.php +++ b/content/fragment/layout-admin.php @@ -10,12 +10,12 @@
-
data("username")?>
-
showContent("panel");?>
+
data('username')?>
+
showContent('panel');?>
-
showContent("header");?>
-
showContent("body");?>
+
showContent('header');?>
+
showContent('body');?>