wangshan 3 days ago
parent
commit
1b0bfa2ff7
2 changed files with 74 additions and 72 deletions
  1. 3 1
      src/jfw/filter/cookie.go
  2. 71 71
      src/jfw/filter/filter.go

+ 3 - 1
src/jfw/filter/cookie.go

@@ -19,8 +19,10 @@ type CookieInfo struct {
 
 // Do 继承过滤器方法
 func (ci *CookieInfo) Do() {
+    log.Println("-----------++++++++++------------")
     //判断 cookie 是否有seo referer标识
-    if seoRefer, err := ci.R.Cookie("SeoRefer"); err != nil && seoRefer.Value != "" {
+    seoRefer, err := ci.R.Cookie("SeoRefer")
+    if err == nil && seoRefer.Value != "" {
         log.Println("-----------seoRefer------------", seoRefer)
     }
     if crr := ci.R.Referer(); !ci.IsLogin && crr != "" {

+ 71 - 71
src/jfw/filter/filter.go

@@ -1,91 +1,91 @@
 package filter
 
 import (
-    "crypto/rsa"
-    "github.com/bwmarrin/snowflake"
-    . "jy/src/jfw/config"
-    "jy/src/jfw/jyutil"
-    "net/http"
-    "regexp"
-    "time"
+	"crypto/rsa"
+	"github.com/bwmarrin/snowflake"
+	. "jy/src/jfw/config"
+	"jy/src/jfw/jyutil"
+	"net/http"
+	"regexp"
+	"time"
 
-    util "app.yhyue.com/moapp/jybase/common"
-    fs "app.yhyue.com/moapp/jybase/fsnotify"
-    "app.yhyue.com/moapp/jybase/go-xweb/xweb"
-    fx "app.yhyue.com/moapp/jypkg/filter/xweb"
-    "app.yhyue.com/moapp/jypkg/identity"
-    "app.yhyue.com/moapp/jypkg/public"
+	util "app.yhyue.com/moapp/jybase/common"
+	fs "app.yhyue.com/moapp/jybase/fsnotify"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	fx "app.yhyue.com/moapp/jypkg/filter/xweb"
+	"app.yhyue.com/moapp/jypkg/identity"
+	"app.yhyue.com/moapp/jypkg/public"
 )
 
 var RouteConf struct {
-    ExcludeRoute []string
+	ExcludeRoute []string
 }
 var (
-    ExcludeUrl []*regexp.Regexp
-    PrivateKey *rsa.PrivateKey
-    PublicKey  *rsa.PublicKey
+	ExcludeUrl []*regexp.Regexp
+	PrivateKey *rsa.PrivateKey
+	PublicKey  *rsa.PublicKey
 )
 
 func init() {
-    xweb.AddFilter(&Filter{})
-    go initPrivatePublicKey()
-    go ChanMonitor()
-    Node, _ = snowflake.NewNode(util.Int64All(Seoconfig["node"]))
-    //日志过滤 路由集合
-    go fs.FSNotifyFUNC("sword->%s", "./route.json", true, func() {
-        util.ReadConfig("./route.json", &RouteConf)
-        if len(RouteConf.ExcludeRoute) > 0 {
-            ExcludeUrl = []*regexp.Regexp{}
-            for _, v := range RouteConf.ExcludeRoute {
-                ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
-            }
-        }
-    })
-    time.AfterFunc(1*time.Minute, SaveLogTask)
+	xweb.AddFilter(&Filter{})
+	go initPrivatePublicKey()
+	go ChanMonitor()
+	Node, _ = snowflake.NewNode(util.Int64All(Seoconfig["node"]))
+	//日志过滤 路由集合
+	go fs.FSNotifyFUNC("sword->%s", "./route.json", true, func() {
+		util.ReadConfig("./route.json", &RouteConf)
+		if len(RouteConf.ExcludeRoute) > 0 {
+			ExcludeUrl = []*regexp.Regexp{}
+			for _, v := range RouteConf.ExcludeRoute {
+				ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
+			}
+		}
+	})
+	time.AfterFunc(1*time.Minute, SaveLogTask)
 }
 
 type Filter struct {
 }
 
 func (f *Filter) Do(w http.ResponseWriter, r *http.Request) bool {
-    session := xweb.RootApp().SessionManager.Session(r, w)
-    getSession := session.GetMultiple()
-    if getSession["userId"] != nil && getSession["mgoUserId"] == nil && util.Int64All(getSession["positionType"]) == 0 {
-        session.Set("mgoUserId", getSession["userId"])
-    }
-    if getSession["base_user_id"] != nil && getSession["positionId"] == nil {
-        identity.SwitchToBest(util.Int64All(getSession["base_user_id"]), session, Middleground, &public.MQFW, false)
-    }
-    if !(&AnonymousAuth{w, r, session, getSession, make(map[string]interface{})}).Do() {
-        return false
-    }
-    (&CookieInfo{w, r, getSession["userId"] != nil, session}).Do()
-    (&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
-    if !(&logFilter{w, r, session, getSession, make(map[string]interface{})}).Do() {
-        return false
-    }
-    //新版登录时间延长
-    if !(&SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
-        return false
-    }
-    if !(&jyutil.SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
-        return false
-    }
+	session := xweb.RootApp().SessionManager.Session(r, w)
+	getSession := session.GetMultiple()
+	if getSession["userId"] != nil && getSession["mgoUserId"] == nil && util.Int64All(getSession["positionType"]) == 0 {
+		session.Set("mgoUserId", getSession["userId"])
+	}
+	if getSession["base_user_id"] != nil && getSession["positionId"] == nil {
+		identity.SwitchToBest(util.Int64All(getSession["base_user_id"]), session, Middleground, &public.MQFW, false)
+	}
+	if !(&AnonymousAuth{w, r, session, getSession, make(map[string]interface{})}).Do() {
+		return false
+	}
+	(&CookieInfo{w, r, getSession["userId"] != nil, session}).Do()
+	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
+	if !(&logFilter{w, r, session, getSession, make(map[string]interface{})}).Do() {
+		return false
+	}
+	//新版登录时间延长
+	if !(&SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
+		return false
+	}
+	if !(&jyutil.SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
+		return false
+	}
 
-    if !(&mergeFilter{w, r, session, getSession}).Do() {
-        return false
-    }
-    if !(&phoneFilter{w, r, session, getSession}).Do() {
-        return false
-    }
-    if !(&pcFilter{w, r, session, getSession}).Do() {
-        return false
-    }
-    if !(&salesFilter{w, r, session, getSession}).Do() {
-        return false
-    }
-    if !(&pcSalesFilter{w, r, session, getSession}).Do() {
-        return false
-    }
-    return true
+	if !(&mergeFilter{w, r, session, getSession}).Do() {
+		return false
+	}
+	if !(&phoneFilter{w, r, session, getSession}).Do() {
+		return false
+	}
+	if !(&pcFilter{w, r, session, getSession}).Do() {
+		return false
+	}
+	if !(&salesFilter{w, r, session, getSession}).Do() {
+		return false
+	}
+	if !(&pcSalesFilter{w, r, session, getSession}).Do() {
+		return false
+	}
+	return true
 }