浏览代码

Update Session Get func && handler contruct bypass control

HonorLee 6 年之前
父节点
当前提交
450dea126f
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. 3 2
      system/lib/core/router.js
  2. 6 1
      system/lib/core/session.js

+ 3 - 2
system/lib/core/router.js

@@ -38,8 +38,9 @@ var Router ={
         try {
         try {
             let handler = require(handlerFile);
             let handler = require(handlerFile);
             if(typeof handler[method]==='function'){
             if(typeof handler[method]==='function'){
-                if(typeof handler['__construct']==='function') handler['__construct'](req,res);
-                handler[method](req,res);
+                let noBypass = true;
+                if(typeof handler['__construct']==='function') noBypass = handler['__construct'](req,res);
+                if(noBypass) handler[method](req,res);
             }else{
             }else{
                 Router._error('Handler ['+handlerFile+'] no such method "'+method+'"',res);
                 Router._error('Handler ['+handlerFile+'] no such method "'+method+'"',res);
             }
             }

+ 6 - 1
system/lib/core/session.js

@@ -20,7 +20,7 @@ var Session = {
         FILE.writeFileSync(Core.Path.Session + sessionid,JSON.stringify(sessionData),'UTF-8');
         FILE.writeFileSync(Core.Path.Session + sessionid,JSON.stringify(sessionData),'UTF-8');
         return sessionid;
         return sessionid;
     },
     },
-    get:function(sessionid){
+    get:function(sessionid,key){
         if(!sessionid) return null;
         if(!sessionid) return null;
         let sessionData;
         let sessionData;
         try{
         try{
@@ -32,6 +32,11 @@ var Session = {
         }catch(e){
         }catch(e){
             sessionData = null;
             sessionData = null;
         }
         }
+        if(key && sessionData){
+            if(sessionData[key]!=undefined) return sessionData[key];
+        }else{
+            return null;
+        }
         return sessionData;
         return sessionData;
     },
     },
     clear:function(sessionid){
     clear:function(sessionid){