Преглед изворни кода

Merge branch 'develop' of http://code.dashoo.cn/chengjian/opms_backend into develop

Cheng Jian пре 3 година
родитељ
комит
202c3e0347

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

@@ -36,7 +36,7 @@ type LoginUserRes struct {
 
 
 // SysUserSearchReq 用户搜索请求参数
 // SysUserSearchReq 用户搜索请求参数
 type SysUserSearchReq struct {
 type SysUserSearchReq struct {
-	DeptId   string `json:"deptId"` //部门id
+	DeptId   int    `json:"deptId"` //部门id
 	DeptIds  []int  //所属部门id数据
 	DeptIds  []int  //所属部门id数据
 	Phone    string `json:"phone"`
 	Phone    string `json:"phone"`
 	Status   string `json:"status"`
 	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 + "%"
 		keyWords := "%" + req.KeyWords + "%"
 		userModel = userModel.Where("user_name like ? or  nick_name like ?", keyWords, 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 {
 	if len(req.DeptIds) != 0 {
 		userModel = userModel.Where("dept_id in (?)", req.DeptIds)
 		userModel = userModel.Where("dept_id in (?)", req.DeptIds)
 	}
 	}

+ 9 - 3
opms_admin/config/config.toml

@@ -16,7 +16,13 @@
 [database]
 [database]
     [[database.default]]
     [[database.default]]
         Debug = true
         Debug = true
-        link = "mysql:root:Dashoo#190801@tcp(127.0.0.1:3306)/dashoo_crm"
+        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/dashoo_crm"
 
 
-[micro_srv]
-    auth = "dashoo.labsop.auth-2.1"
+# token认证设置
+[gtoken]
+    # 缓存模式 1 gcache 2 gredis
+    cache-mode = 1
+    # 是否支持多端登录
+    multi-login = true
+    # 必须16,24或32个字母
+    encrypt-key = "jwtdashoo-191225"

+ 2 - 1
opms_admin/main.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"dashoo.cn/micro/app/handler"
 	"dashoo.cn/micro/app/handler"
 	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/micro_srv"
-
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/frame/g"
 	"github.com/smallnest/rpcx/protocol"
 	"github.com/smallnest/rpcx/protocol"
 )
 )
@@ -35,6 +34,7 @@ func main() {
 // AuthExcludePaths 设定不需要认证的路径
 // AuthExcludePaths 设定不需要认证的路径
 var AuthExcludePaths = []string{
 var AuthExcludePaths = []string{
 	"/Auth/Login",
 	"/Auth/Login",
+	"/Auth/ValidToken",
 	"/Role/GetRoleList",
 	"/Role/GetRoleList",
 	"/Common/GetCaptchaImg",
 	"/Common/GetCaptchaImg",
 	"/Model/*",
 	"/Model/*",
@@ -45,6 +45,7 @@ var AuthExcludePaths = []string{
 
 
 // 处理Auth
 // 处理Auth
 func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
 func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
+	ctx = context.WithValue(ctx, "NotAuthSrv", true)
 	// token拦截器
 	// token拦截器
 	err := micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
 	err := micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
 	return err
 	return err

+ 19 - 12
opms_libary/micro_srv/micro_srv.go

@@ -199,13 +199,16 @@ func HandleAuth(ctx context.Context, req *protocol.Message, token string, authEx
 	path := "/" + req.ServicePath + "/" + req.ServiceMethod
 	path := "/" + req.ServicePath + "/" + req.ServiceMethod
 	//g.Log().Info("reqPath: ", path)
 	//g.Log().Info("reqPath: ", path)
 	//g.Log().Info("token: ", token)
 	//g.Log().Info("token: ", token)
-	req.Metadata["authExclude"] = "true"
 
 
 	if authPath(path, authExcludePaths) {
 	if authPath(path, authExcludePaths) {
 		req.Metadata["authExclude"] = "false"
 		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")
 		//return errors.New("InvalidToken")
 		if rsp.Code != 0 {
 		if rsp.Code != 0 {
@@ -259,23 +262,27 @@ func authPath(urlPath string, authExcludePaths []string) bool {
 }
 }
 
 
 // 验证token
 // 验证token
-func validToken(token string) auth.Response {
-	rsp := &auth.Response{}
+func validToken(token string) gtoken.Resp {
+	grsp := gtoken.Resp{}
 	if token == "" {
 	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")
 	authService := InitMicroSrvClient("Auth", "micro_srv.auth")
 	defer authService.Close()
 	defer authService.Close()
+	rsp := &auth.Response{}
 	err := authService.Call(context.TODO(), "ValidToken", token, rsp)
 	err := authService.Call(context.TODO(), "ValidToken", token, rsp)
 	if err != nil {
 	if err != nil {
 		g.Log().Error(err)
 		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验证
 // IsAuthExclude 是否进行auth验证

+ 1 - 1
opms_parent/config/config.toml

@@ -19,4 +19,4 @@
         link = "mysql:root:Dashoo#190801@tcp(127.0.0.1:3306)/dashoo_crm"
         link = "mysql:root:Dashoo#190801@tcp(127.0.0.1:3306)/dashoo_crm"
 
 
 [micro_srv]
 [micro_srv]
-    auth = "dashoo.labsop.auth-2.1"
+    auth = "dashoo.opms.admin-0.0.1,127.0.0.1:8887"