Merge branch 'master' of http://git.roojs.com/Pman.Core
[Pman.Core] / DataObjects / Person.php
index 8b9b204..c80e75e 100644 (file)
@@ -243,7 +243,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             
             return false;
             
-            $ff->page->jerr("Login not permited to outside companies");
+            //$ff->page->jerr("Login not permited to outside companies");
         }
         return true;
         
@@ -268,12 +268,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $u = DB_DataObject::factory($this->tableName());
             if ($a->id && $u->get($a->id)) { //&& strlen($u->passwd)) {
               
-                return $u->verifyAuth();
+                return $u->verifyAuth();  // got authentication...
                 
     
             }
             
             unset($_SESSION[get_class($this)][$sesPrefix .'-auth']);
+            unset($_SESSION[get_class($this)][$sesPrefix .'-timeout']);
+            setcookie('Pman.timeout', -1, time() + (30*60), '/');
             
         }
         if (!$this->canInitializeSystem()) {
@@ -309,6 +311,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         //var_dump($ff->Pman['local_autoauth']);         var_dump($_SERVER); exit;
         $u = DB_DataObject::factory($this->tableName());
         $ff = HTML_FlexyFramework::get();
+        
         if (!empty($ff->Pman['local_autoauth']) && 
             (!empty($_SERVER['SERVER_ADDR'])) &&
             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
@@ -380,14 +383,19 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $u = DB_DataObject::factory($this->tableName()); // allow extending this ...
             $u->autoJoin();
             if ($u->get($a->id)) { /// && strlen($u->passwd)) {  // should work out the pid .. really..
+                
+                $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = time() + (30*60); // eg. 30 minutes
+                setcookie('Pman.timeout', time() + (30*60), time() + (30*60), '/');
+                
                 $user = clone ($u);
                 
-                if(!empty($a->_extra)){
-                    $user->_extra = $a->_extra;
-                }
                 return clone($user);
+            
             }
             unset($_SESSION[get_class($this)][$sesPrefix .'-auth']);
+            unset($_SESSION[get_class($this)][$sesPrefix .'-timeout']);
+            setcookie('Pman.timeout', -1, time() + (30*60), '/');
+            
         }
         
         
@@ -458,9 +466,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
         $d = $p->toArray();
         
-        if(!empty($this->_extra)){
-            $d['_extra'] = $this->_extra;
-        }
+        $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = time() + (30*60); // eg. 30 minutes
+        setcookie('Pman.timeout', time() + (30*60), time() + (30*60), '/');
         
         //var_dump(array(get_class($this),$sesPrefix .'-auth'));
         $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize((object)$d);
@@ -475,6 +482,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
         $sesPrefix = $this->sesPrefix();
         
+        $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = -1;
+        
         $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
         
     }    
@@ -511,10 +520,10 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
        
     }      
     
-    function generatePassword() // genearte a password (add set 'rawPasswd' to it's value)
+    function generatePassword($length = 5) // genearte a password (add set 'rawPasswd' to it's value)
     {
         require_once 'Text/Password.php';
-        $this->rawPasswd = strtr(ucfirst(Text_Password::create(5)).ucfirst(Text_Password::create(5)), array(
+        $this->rawPasswd = strtr(ucfirst(Text_Password::create($length)).ucfirst(Text_Password::create($length)), array(
         "a"=>"4", "e"=>"3",  "i"=>"1",  "o"=>"0", "s"=>"5",  "t"=>"7"));
         $this->setPassword($this->rawPasswd);
         return $this->rawPasswd;
@@ -683,6 +692,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (!isset($pcache[$this->id])) {
             $pcache[$this->id] = $this->getPerms();
         }
+        
        // echo "<PRE>";print_r($pcache[$au->id]);
        // var_dump($pcache[$au->id]);
         if (empty($pcache[$this->id][$name])) {
@@ -1156,6 +1166,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         }
     }
     
+    // this is for the To: "{getEmailName()}" <email@address>
+    // not good for Dear XXXX, - use {person.firstname} for that.
     function getEmailName()
     {
         $name = array();
@@ -1176,7 +1188,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             
             $name = array_filter($name);
             
-            return $name;
+            return implode(' ', $name);
         }
         
         return $this->email;