|
@@ -1,7 +1,6 @@
|
|
|
package middleware
|
|
|
|
|
|
import (
|
|
|
- "log"
|
|
|
"strings"
|
|
|
|
|
|
. "bp.jydev.jianyu360.cn/BaseService/gateway/common/gatecode"
|
|
@@ -20,25 +19,20 @@ import (
|
|
|
func filterBefore(r *ghttp.Request) error {
|
|
|
ctx := router.GetGContext(r.GetCtx())
|
|
|
rule := ctx.RouterRule
|
|
|
-
|
|
|
if rule.SessCheck.NeedCheck() {
|
|
|
|
|
|
uCheck, eCheck := rule.SessCheck.CheckUserSession(), rule.SessCheck.CheckEntSession()
|
|
|
|
|
|
+ //注入用户身份
|
|
|
+ infusionIdentity(r, ctx.Sess, rule.AppId)
|
|
|
+
|
|
|
if uCheck && ctx.Sess.UserId == "" {
|
|
|
return NewErrorWithCode(GLOBAL_ERR_NOTLOGIN)
|
|
|
}
|
|
|
if eCheck && ctx.Sess.EntId == 0 {
|
|
|
return NewErrorWithCode(GLOBAL_ERR_NOENT_SELECT)
|
|
|
}
|
|
|
-
|
|
|
- // 用户身份注入请求体中
|
|
|
- if uCheck || eCheck {
|
|
|
- infusionIdentity(r, ctx.Sess, rule.AppId)
|
|
|
- }
|
|
|
}
|
|
|
- //APPID注入请求体
|
|
|
- infusionAppid(r, rule.AppId)
|
|
|
|
|
|
//校验账户状态,校验认证状态
|
|
|
if rule.AccountCheck.NeedCheck() || rule.AuthCheck.NeedCheck() {
|
|
@@ -91,16 +85,22 @@ func filterAfter(r *ghttp.Request) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// infusionIdentity 用户身份注入Header
|
|
|
+// infusionIdentity 用户身份注入Header 有则注入
|
|
|
func infusionIdentity(r *ghttp.Request, sess *router.JySession, appId string) {
|
|
|
- r.Header.Set("userId", sess.UserId)
|
|
|
- r.Header.Set("entName", sess.EntName)
|
|
|
- r.Header.Set("entId", gconv.String(sess.EntId))
|
|
|
- r.Header.Set("phone", sess.Phone)
|
|
|
- r.Header.Set("entUserId", gconv.String(sess.EntUserId))
|
|
|
-}
|
|
|
-
|
|
|
-// infusionAppid appid注入Header
|
|
|
-func infusionAppid(r *ghttp.Request, appId string) {
|
|
|
r.Header.Set("appId", appId)
|
|
|
+ if sess.UserId != "" {
|
|
|
+ r.Header.Set("userId", sess.UserId)
|
|
|
+ }
|
|
|
+ if sess.EntName != "" {
|
|
|
+ r.Header.Set("entName", sess.EntName)
|
|
|
+ }
|
|
|
+ if sess.EntId > 0 {
|
|
|
+ r.Header.Set("entId", gconv.String(sess.EntId))
|
|
|
+ }
|
|
|
+ if sess.Phone != "" {
|
|
|
+ r.Header.Set("phone", sess.Phone)
|
|
|
+ }
|
|
|
+ if sess.EntUserId > 0 {
|
|
|
+ r.Header.Set("entUserId", gconv.String(sess.EntUserId))
|
|
|
+ }
|
|
|
}
|