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 '
