Browse Source

feature:基础模块开发
1.修改验证token方式

ZZH-wl 3 years ago
parent
commit
c4d39aa80c

+ 1 - 1
opms_admin/app/model/sys_user.go

@@ -36,7 +36,7 @@ type LoginUserRes struct {
 
 // SysUserSearchReq 用户搜索请求参数
 type SysUserSearchReq struct {
-	DeptId   string `json:"deptId"` //部门id
+	DeptId   int    `json:"deptId"` //部门id
 	DeptIds  []int  //所属部门id数据
 	Phone    string `json:"phone"`
 	Status   string `json:"status"`

+ 3 - 0
opms_admin/app/service/sys_user.go

@@ -71,6 +71,9 @@ func (s *userService) GetUserList(req *model.SysUserSearchReq) (total int, userL
 		keyWords := "%" + req.KeyWords + "%"
 		userModel = userModel.Where("user_name like ? or  nick_name like ?", keyWords, keyWords)
 	}
+	if req.DeptId != 0 {
+		userModel = userModel.Where("dept_id", req.DeptId)
+	}
 	if len(req.DeptIds) != 0 {
 		userModel = userModel.Where("dept_id in (?)", req.DeptIds)
 	}

+ 1 - 1
opms_admin/main.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"dashoo.cn/micro/app/handler"
 	"dashoo.cn/opms_libary/micro_srv"
-
 	"github.com/gogf/gf/frame/g"
 	"github.com/smallnest/rpcx/protocol"
 )
@@ -45,6 +44,7 @@ var AuthExcludePaths = []string{
 
 // 处理Auth
 func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
+	ctx = context.WithValue(ctx, "NotAuthSrv", true)
 	// token拦截器
 	err := micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
 	return err

+ 19 - 11
opms_libary/micro_srv/micro_srv.go

@@ -203,9 +203,13 @@ func HandleAuth(ctx context.Context, req *protocol.Message, token string, authEx
 
 	if authPath(path, authExcludePaths) {
 		req.Metadata["authExclude"] = "false"
-
-		//rsp := validToken(token)
-		rsp := gtoken.GFToken.ValidToken(token)
+		var rsp gtoken.Resp
+		notAuthSrv := ctx.Value("NotAuthSrv")
+		if notAuthSrv != nil && notAuthSrv.(bool) {
+			rsp = gtoken.GFToken.ValidToken(token)
+		} else {
+			rsp = validToken(token)
+		}
 
 		//return errors.New("InvalidToken")
 		if rsp.Code != 0 {
@@ -259,23 +263,27 @@ func authPath(urlPath string, authExcludePaths []string) bool {
 }
 
 // 验证token
-func validToken(token string) auth.Response {
-	rsp := &auth.Response{}
+func validToken(token string) gtoken.Resp {
+	grsp := gtoken.Resp{}
 	if token == "" {
-		rsp.Code = 401
-		rsp.Msg = "valid token empty"
-		return *rsp
+		grsp.Code = 401
+		grsp.Msg = "valid token empty"
+		return grsp
 	}
 
 	authService := InitMicroSrvClient("Auth", "micro_srv.auth")
 	defer authService.Close()
+	rsp := &auth.Response{}
 	err := authService.Call(context.TODO(), "ValidToken", token, rsp)
 	if err != nil {
 		g.Log().Error(err)
-		rsp.Code = 401
-		return *rsp
+		grsp.Code = 401
+		return grsp
 	}
-	return *rsp
+	grsp.Code = int(rsp.Code)
+	grsp.Msg = rsp.Msg
+	grsp.Data = rsp.Data
+	return grsp
 }
 
 // IsAuthExclude 是否进行auth验证