Browse Source

Update Session Get func && handler contruct bypass control

HonorLee 6 years ago
parent
commit
450dea126f
2 changed files with 9 additions and 3 deletions
  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 {
             let handler = require(handlerFile);
             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{
                 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');
         return sessionid;
     },
-    get:function(sessionid){
+    get:function(sessionid,key){
         if(!sessionid) return null;
         let sessionData;
         try{
@@ -32,6 +32,11 @@ var Session = {
         }catch(e){
             sessionData = null;
         }
+        if(key && sessionData){
+            if(sessionData[key]!=undefined) return sessionData[key];
+        }else{
+            return null;
+        }
         return sessionData;
     },
     clear:function(sessionid){