DataObjects/Images.php
[Pman.Core] / DataObjects / Core_person.php
index 7b01af3..555936b 100644 (file)
@@ -519,12 +519,26 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         
         return md5(implode(',' ,  array($month, $this->email , $this->passwd, $this->id)));
     } 
-    function checkPassword($val)
+    
+    function checkTwoFactorAuthentication($val)
     {
-        if(!empty($this->oath_key)){
-            return $this->checkTwoFactorAuthentication($val);
+        require_once 'System.php';
+        
+        $oathtool = System::which('oathtool');
+        
+        if (!$oathtool) {
+            return false;
         }
         
+        $cmd = "{$oathtool} --totp --base32 {$this->oath_key}";
+        
+        $password = exec($cmd);
+        
+        return ($password == $val) ? true : false;
+    }
+    
+    function checkPassword($val)
+    {
         if (substr($this->passwd,0,1) == '$') {
             if (function_exists('pasword_verify')) {
                 return password_verify($val, $this->passwd);
@@ -1011,14 +1025,14 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         }
         
         /*
-         * Seems we never expose oath_key, so...
+         * Seems we never expose oath_key / passwd, so...
          */
+        
+        $this->_extra_cols = array('length_passwd', 'length_oath_key');
+        
         $this->selectAdd("
-            CASE WHEN core_person.oath_key != '' THEN
-                TRUE
-            ELSE
-                FALSE
-            END AS has_oath_key
+            LENGTH({$this->tableName()}.passwd) AS length_passwd,
+            LENGTH({$this->tableName()}.oath_key) AS length_oath_key
         ");
         
     }
@@ -1308,20 +1322,6 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         return true;
     }
     
-    function toRooSingleArray($au, $q)
-    {
-        $ret = $this->toArray();
-        
-        $core_person = DB_DataObject::factory('core_person');
-        $core_person->selectAdd('core_person.oath_key AS oath_key');
-        $core_person->get($this->id);
-        
-        $ret['has_oath_key'] = (empty($core_person->oath_key)) ? 0 : 1;
-        
-        return $ret;
-        
-    }
-    
     function beforeUpdate($old, $q, $roo)
     {
         if(!empty($q['_generate_oath_key'])){
@@ -1362,11 +1362,15 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
             return false;
         }
         
+        $issuer = (empty($this->name)) ? rawurlencode('ROOJS') : rawurlencode($this->name);
+        
+        $uri = "otpauth://totp/{$issuer}:{$this->email}?secret={$this->oath_key}&issuer={$issuer}&algorithm=SHA1&digits=6&period=30";
+        
         require_once 'Image/QRCode.php';
         
         $qrcode = new Image_QRCode();
         
-        $image = $qrcode->makeCode('test', array(
+        $image = $qrcode->makeCode($uri, array(
             'output_type' => 'return'
         ));
         
@@ -1375,32 +1379,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
         $base64 = base64_encode(ob_get_contents());
         ob_end_clean();
         
-        print_R($base64);exit;
-        
-        $issuer = (empty($this->name)) ? rawurlencode('ROOJS') : rawurlencode($this->name);
-        
-        $uri = "otpauth://totp/{$issuer}:{$this->email}?secret={$this->oath_key}&issuer={$issuer}&algorithm=SHA1&digits=6&period=30";
-        
-        $base64 = base64_encode(file_get_contents("https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl={$uri}"));
-        
         return "data:image/png;base64,{$base64}";
     }
     
-    function checkTwoFactorAuthentication($val)
-    {
-        require_once 'System.php';
-        
-        $oathtool = System::which('oathtool');
-        
-        if (!$oathtool) {
-            return false;
-        }
-        
-        $cmd = "{$oathtool} --totp --base32 {$this->oath_key}";
-        
-        $password = exec($cmd);
-        
-        return ($password == $val) ? true : false;
-    }
-    
  }