DataObjects/Core_enum.php
[Pman.Core] / DataObjects / Core_person.php
index fd22f41..c8a8863 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Table Definition for Person
  */
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
 
 
 class Pman_Core_DataObjects_Core_person extends DB_DataObject 
@@ -151,7 +151,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $decoder = new Mail_mimeDecode($mailtext);
         $parts = $decoder->getSendArray();
         
-        if (PEAR::isError($parts)) {
+        if (is_a($parts,'PEAR_Error')) {
             return $parts;
             //echo "PROBLEM: {$parts->message}";
             //exit;
@@ -263,8 +263,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         if (!empty($_SESSION[get_class($this)][$sesPrefix .'-auth'])) {
             // in session...
             $a = unserialize($_SESSION[get_class($this)][$sesPrefix .'-auth']);
-            
-            
+             
             $u = DB_DataObject::factory($this->tableName());
             if ($a->id && $u->get($a->id)) { //&& strlen($u->passwd)) {
               
@@ -293,8 +292,9 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
             $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize($u);
             return true; 
         }
-        
+        //die("test init");
         if (!$this->canInitializeSystem()) {
+          //  die("can not init");
             return false;
         }
         
@@ -304,8 +304,17 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         if (!empty($ff->Pman['local_autoauth']) && 
             ($ff->Pman['local_autoauth'] === true) &&
             (!empty($_SERVER['SERVER_ADDR'])) &&
-            ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
-            ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')  
+            (
+                (
+                    $_SERVER['SERVER_ADDR'] == '127.0.0.1' &&
+                    $_SERVER['REMOTE_ADDR'] == '127.0.0.1'
+                )
+                ||
+                (
+                    $_SERVER['SERVER_ADDR'] == '::1' &&
+                    $_SERVER['REMOTE_ADDR'] == '::1'
+                )
+            )
         ) {
             $group = DB_DataObject::factory('core_group');
             $group->get('name', 'Administrators');
@@ -330,8 +339,17 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         
         if (!empty($ff->Pman['local_autoauth']) && 
             (!empty($_SERVER['SERVER_ADDR'])) &&
-            ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
-            ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')  &&
+            (
+                (
+                    $_SERVER['SERVER_ADDR'] == '127.0.0.1' &&
+                    $_SERVER['REMOTE_ADDR'] == '127.0.0.1'
+                )
+                ||
+                (
+                    $_SERVER['SERVER_ADDR'] == '::1' &&
+                    $_SERVER['REMOTE_ADDR'] == '::1'
+                )
+            ) &&
             ($default_admin ||  $u->get('email', $ff->Pman['local_autoauth']))
         ) {
             $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize($default_admin ? $default_admin : $u);
@@ -350,9 +368,11 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $u->whereAdd(' LENGTH(passwd) > 0');
         $n = $u->count();
         $_SESSION[get_class($this)][$sesPrefix .'-empty']  = $n;
-        $error =  PEAR::getStaticProperty('DB_DataObject','lastError');
-        if ($error) {
-            die($error->toString()); // not really a good thing to do...
+        if (class_exists('PEAR')) {
+            $error =  PEAR::getStaticProperty('DB_DataObject','lastError');
+            if ($error) {
+                die($error->toString()); // not really a good thing to do...
+            }
         }
         if (!$n){ // authenticated as there are no users in the system...
             return true;
@@ -364,6 +384,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
     
     function canInitializeSystem()
     {
+        
         return !strcasecmp(get_class($this) , __CLASS__);
     }
     
@@ -444,7 +465,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         }
         
         // open up iptables at login..
-        $dbname = $this->database();
+        $dbname = $this->databaseNickname();
         touch( '/tmp/run_pman_admin_iptables-'.$dbname);
          
         // refresh admin group if we are logged in as one..
@@ -501,8 +522,11 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
     function checkPassword($val)
     {
         
+        
         if (substr($this->passwd,0,1) == '$') {
-            
+            if (function_exists('pasword_verify')) {
+                return password_verify($val, $this->passwd);
+            }
             return crypt($val,$this->passwd) == $this->passwd ;
         }
         // old style md5 passwords...- cant be used with courier....
@@ -511,6 +535,10 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
     
     function setPassword($value) 
     {
+        if (function_exists('pasword_hash')) {
+            return password_hash($value);
+        }
+        
         $salt='';
         while(strlen($salt)<9) {
             $salt.=chr(rand(64,126));
@@ -969,7 +997,6 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
             $this->setPassword($ar['passwd1']);
         }
         
-        
         if (    $this->id &&
                 ($this->email == $roo->old->email)&&
                 ($this->company_id == $roo->old->company_id)
@@ -979,6 +1006,13 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         if (empty($this->email)) {
             return true;
         }
+        // this only applies to our owner company..
+        $c = $this->company();
+        if (empty($c->comptype_name) || $c->comptype_name != 'OWNER') {
+            return true;
+        }
+        
+        
         $xx = DB_Dataobject::factory($this->tableName());
         $xx->setFrom(array(
             'email' => $this->email,
@@ -1206,9 +1240,9 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         
         $appname = empty($ff->appNameShort) ? $ff->project : $ff->project . '-' . $ff->appNameShort;
         
-        $db = $this->getDatabaseConnection();
+        $dname = method_exists($this, 'getDatabaseConnection') ? $this->getDatabaseConnection()->dsn['database'] : $this->databaseNickname();
         
-        $sesPrefix = $appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
+        $sesPrefix = $appname.'-' .get_class($this) .'-' . $dname;
 
         return $sesPrefix;
     }
@@ -1220,12 +1254,12 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $db = $this->getDatabaseConnection();
         
         $ff = HTML_FlexyFramework::get();
-        print_R($ff);exit;
-        if(empty($ff->Pman) || empty($ff->Pman->login_public)){
+        
+        if(empty($ff->Pman) || empty($ff->Pman['login_public'])){
             return false;
         }
         
-        $sesPrefix = $ff->Pman->login_public . '-' .get_class($this) .'-'.$db->dsn['database'] ;
+        $sesPrefix = $ff->Pman['login_public'] . '-' .get_class($this) .'-'.$db->dsn['database'] ;
         
         $p = DB_DAtaObject::Factory($this->tableName());
         $p->get($this->pid());