check file exists
[Pman.Core] / VerifyAccess.php
index ff79ad5..ba8d641 100644 (file)
@@ -14,49 +14,82 @@ class Pman_Core_VerifyAccess extends Pman
         return true;
     }
     
-    function get($id)
+    function get($id='', $opts = array())
     {
+        @list($id, $key) = explode('/', $id);
+        
+        if(empty($id) || empty($key)){
+            $this->jerr('Invalid URL');
+        }
+        
+        $core_ip_access = DB_DataObject::factory('core_ip_access');
+        
+        if(!$core_ip_access->get($id) || $core_ip_access->authorized_key != $key){
+            $this->jerr('This URL is broken');
+        }
         
+        $ff = HTML_FlexyFramework::get();
+        
+        if(empty($ff->Pman['ip_management']) || empty($ff->Pman['XMPP']) || empty($ff->Pman['XMPP']['to'])) {
+            $this->jerr('[System Error] This site does not using IP management');
+        }
+        
+//        $ff->Pman['XMPP']['to'] = 'edward@roojs.com'; // testing...
+        
+        $core_person = DB_DataObject::factory('core_person');
+        
+        if(!$core_person->get('email', $ff->Pman['XMPP']['to'])) {
+            $this->jerr('[System Error] Please setup the XMPP correctly');
+        }
         
         return;
         
     }
     
-    function validate($id)
+    function post($base)
     {
-        $ret = array(
-            'is_valid' => true,
-            'errorMsg' => ''
-        );
+        $core_ip_access = DB_DataObject::factory('core_ip_access');
         
-        @list($id, $key) = explode('/', $id);
+        if(
+                empty($_REQUEST['id']) || 
+                empty($_REQUEST['authorized_key']) ||
+                !$core_ip_access->get($_REQUEST['id']) ||
+                $core_ip_access->authorized_key != $_REQUEST['authorized_key']
+        ){                
+            $this->jerr('Invalid URL');
+        }
         
-        if(empty($id) || empty($key)){
-            return false;
+        if(!empty($_REQUEST['_to_data'])){
+            $this->jdata($core_ip_access->toArray());
         }
         
-        $core_ip_access = DB_DataObject::factory('core_ip_access');
+        $ff = HTML_FlexyFramework::get();
         
+        if(empty($ff->Pman['ip_management']) || empty($ff->Pman['XMPP']) || empty($ff->Pman['XMPP']['to'])) {
+            $this->jerr('[System Error] This site does not using IP management');
+        }
         
-        $ff = HTML_FlexyFramework::get();
+//        $ff->Pman['XMPP']['to'] = 'edward@roojs.com'; // testing...
         
         $core_person = DB_DataObject::factory('core_person');
         
+        if(!$core_person->get('email', $ff->Pman['XMPP']['to'])) {
+            $this->jerr('[System Error] Please setup the XMPP correctly');
+        }
         
-        $ff->Pman['XMPP']['to'] = 'edward@roojs.com'; // testing...
+        $o = clone($core_ip_access);
+        
+        $core_ip_access->setFrom(array(
+            'status' => empty($_REQUEST['status']) ? 0 : $_REQUEST['status'],
+            'expire_dt' => ($_REQUEST['status'] != -2 || empty($_REQUEST['expire_dt'])) ? '' : date('Y-m-d', strtotime($_REQUEST['expire_dt'])),
+            'authorized_by' => $core_person->id
+        ));
+        
+        $core_ip_access->update($o);
+        
+        $this->jok('OK');
         
-        if(
-                empty($id) ||
-                empty($key) ||
-                empty($ff->Pman['ip_management']) || 
-                empty($ff->Pman['XMPP']) ||
-                empty($ff->Pman['XMPP']['to']) ||
-                !$core_person->get('email', $ff->Pman['XMPP']['to']) ||
-                !$core_ip_access->get($id) ||
-                $core_ip_access->authorized_key != $key
-        ) {
-            $this->jerr('Invalid URL');
-        }
     }
     
+    
 }