Added rudimentary support for UID/GID
authorThomas Mudrunka <tomas@mudrunka.cz>
Fri, 23 Sep 2011 18:24:24 +0000 (20:24 +0200)
committerThomas Mudrunka <tomas@mudrunka.cz>
Fri, 23 Sep 2011 18:24:24 +0000 (20:24 +0200)
INSTALL.md
index.php
lib/Sklad_Auth.class/common.php
lib/Sklad_Auth.class/internal.php
sklad.conf.php.example

index e8631338e1db17edf94b8877a3ae1a6eb4cf5011..2e8cd78da276d44efd50e0318654046156d5b83e 100644 (file)
@@ -16,4 +16,4 @@
      * Set INSTANCE\_ID (this is how you call your instalation, hostname, organization, etc...)
      * Set BARCODE\_TYPE (that will be used for printing barcodes)
      * Set BARCODE\_PREFIX (this will be used for generating unique barcodes if you have more instalations)
-     * Set $fake\_lms\_users (If you want to use login credentials different from your DB user/password)
+     * Set $internal\_auth\_users (If you want to use login credentials different from your DB user/password)
index 7bde575b2316de018ac7681e3cc5214319f8d7db..db9921d1960afb4b9d6b7f14adb23b29ae01c7fa 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -151,18 +151,21 @@ class HTML {
 * @author   Tomas Mudrunka
 */
 class Sklad_HTML extends HTML { //TODO: Split into few more methods
-       function header($title='', $uid=0, $user='') {
+       function header($title='', $user=array()) {
                $home = URL_HOME;
                $script = $_SERVER['SCRIPT_NAME'];
                $search = htmlspecialchars(@trim($_GET['q']));
                $message = strip_tags(@trim($_GET['message']),'<a><b><u><i>');
                $instance = INSTANCE_ID != '' ? '/'.INSTANCE_ID : '';
+               $user_id = htmlspecialchars($user['id']);
+               $user_gid = htmlspecialchars($user['gid']);
+               $user_name = htmlspecialchars($user['name']);
                //$title = T($title); //TODO
 
                $html = $this->head("SōkoMan$title");
                $html .= <<<EOF
 <h1 style="display: inline;"><a href="$script/">SōkoMan</a><small>$instance$title</small></h1>
-<div style="float:right">Loged in as $user [UID $uid]</div>
+<div style="float:right">Loged in as <b>$user_name</b> [UID: <b>$user_id</b>; GID: <b>$user_gid</b>]</div>
 
 <style type="text/css">
 * { font-family: arial; }
@@ -607,8 +610,8 @@ class Sklad_DB extends PDO {
                                                        $row_quoted[$column] = '0';
                                                        break;
                                                case $table.'_author':
-                                                       $row_quoted[$column] = $this->auth->get_authorized_user_id();
-                                                       //die($this->auth->get_authorized_user_id().'=USER');
+                                                       $row_quoted[$column] = $this->auth->get_user_id();
+                                                       //die($this->auth->get_user_id().'=USER');
                                                        break;
                                        }
                                }
@@ -843,7 +846,7 @@ class Sklad_UI {
                //Sephirot:
                if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]='';
                if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcode') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost...
-                       echo $this->html->header($PATH_INFO,$this->db->auth->get_authorized_user_id());
+                       echo $this->html->header($PATH_INFO,$this->db->auth->get_user());
                switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible
                        case 'test':    //test
                                die('Tell me why you cry');
index eff35d289ef4b694bd5845943587129cbfaf3d9b..fce075f7a9a92aaf206e550da5ac676e5258b715 100755 (executable)
 * @author   Tomas Mudrunka
 */
 class Sklad_Auth_common {
-       function get_authorized_user_id($die=true) {
-               if(isset($this->authorized_user_id)) return $this->authorized_user_id;
+       function get_user($die=true) {
+               if(isset($this->user)) return $this->user;
                if($die) die('No user authorized!!!');
                return false;
        }
+
+       function get_user_id($die=true) {
+               $user = $this->get_user($die);
+               return $user['id'];
+       }
 }
 
 require_once(BACKEND_AUTH.'.php');
index 1ef39d2a5651689087791cbfcc235c8d98dfb367..9739aa3ed2f170f55085e2e4c969543224eeed2d 100755 (executable)
 */
 class Sklad_Auth extends Sklad_Auth_common { //FAKE!
        function check_auth($user, $pass) {
-               $users = array( //You can specify multiple users in this array
-                       DB_USER => DB_PASS
+               $users = array(
+                       DB_USER => array(DB_PASS,0,0)
                );
-               if(isset($GLOBALS['fake_lms_users'])) $users = $GLOBALS['fake_lms_users'] + $users;
-               $this->authorized_user_id=23; //Auth user_id
-               return (isset($users[$user]) && ($users[$user] == $pass));
+               if(isset($GLOBALS['internal_auth_users'])) $users = $GLOBALS['internal_auth_users'] + $users;
+               if(isset($users[$user][0]) && ($users[$user][0] == $pass)) {
+                       $this->user['name']=$user;
+                       $this->user['id']=$users[$user][1];
+                       $this->user['gid']=$users[$user][2];
+                       return true;
+               }
+               return false;
        }
 }
index 11b44a5e06c7d11e7f9b0842f86da1bd2f0dc9d7..c779f9b9cfc02795fc7944f0345e834712fc5011 100755 (executable)
@@ -17,6 +17,9 @@ define('URL_HOME',            dirname($_SERVER['SCRIPT_NAME']));
 define('URL_IMAGES',           URL_HOME.'/images');
 define('URL_BARCODES',         URL_HOME.'/barcodes');
 
+define('BACKEND_AUTH',         'internal');
+define('BACKEND_ACCOUNTING',   'internal');
+
 define('LOCALE_LANG',          'en');
 
 define('INSTANCE_ID',          '');
@@ -24,6 +27,7 @@ define('INSTANCE_ID',         '');
 define('BARCODE_TYPE',         'code128b');
 define('BARCODE_PREFIX',       'STORE/');
 
-$fake_lms_users = array( //You can specify multiple users in this array
-       DB_USER => DB_PASS
+$internal_auth_users = array( //You can specify multiple users in this array
+       //'username'    => array('password',    'uid','gid'),
+       DB_USER => array(DB_PASS,       0,0)
 );
This page took 0.188407 seconds and 4 git commands to generate.