DataObjects/Core_person.php
[Pman.Core] / DataObjects / Core_person.php
index 3f6753f..7e15e84 100644 (file)
@@ -518,7 +518,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         return md5(implode(',' ,  array($month, $this->email , $this->passwd, $this->id)));
     } 
     
-    function checkTwoFactorAuthentication($val, $oath_key)
+    function checkTwoFactorAuthentication($val)
     {
         // also used in login
         
@@ -526,7 +526,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         
         if(
             empty($this->id) ||
-            empty($oath_key)
+            empty($this->oath_key)
         ) {
             return false;
         }
@@ -674,7 +674,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $aur['oath_key_enable'] = !empty($this->oath_key);
         
         $s = DB_DataObject::Factory('core_setting');
-        $aur['disable_oath'] = empty($s->lookup('core', 'two_factor_authentication')) ? 0 : 1;
+        $aur['disable_oath'] = (bool) $s->lookup('core', 'two_factor_authentication') ? 1 : 0;
         
         return $aur;
     }
@@ -775,8 +775,10 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
                 $roo->jerr('_invalid_person');
             }
             
-            $hash = $this->getOathKey();
+            $hash = $this->generateOathKey();
             
+            $_SESSION[__CLASS__] = isset($_SESSION[__CLASS__]) ? $_SESSION[__CLASS__] : array();
+            $_SESSION[__CLASS__]['oath'] = isset($_SESSION[__CLASS__]['oath']) ? $_SESSION[__CLASS__]['oath'] : array();
             $_SESSION[__CLASS__]['oath'][$person->id] = $hash;
 
             $qrcode = $person->generateQRCode($hash);
@@ -792,14 +794,11 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
             
             $person = DB_DataObject::factory('core_person');
             $person->get($q['id']);
+            $person->oath_key = $_SESSION[__CLASS__]['oath'][$person->id];
             
-            if($person->checkTwoFactorAuthentication(
-                $q['two_factor_auth_code'],
-                $_SESSION[__CLASS__]['oath'][$person->id]
-            )) {
+            if($person->checkTwoFactorAuthentication($q['two_factor_auth_code'])) {
                 
                 $o = clone($person);
-                $person->oath_key = $_SESSION[__CLASS__]['oath'][$person->id];
                 $person->update($o);
                 
                 unset($_SESSION[__CLASS__]['oath'][$person->id]);
@@ -1112,7 +1111,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $this->setFrom($ar);
         
         if(!empty($ar['_enable_oath_key'])){
-            $oath_key = $this->getOathKey();
+            $oath_key = $this->generateOathKey();
         }
         
         if (!empty($ar['passwd1'])) {
@@ -1434,7 +1433,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $this->email = trim($this->email);
     }
     
-    function getOathKey()
+    function generateOathKey()
     {
         require 'Base32.php';