sunsheng 8 months ago
parent
commit
35771f9b5f
3 changed files with 10 additions and 39 deletions
  1. 3 36
      src/api/controller.go
  2. 2 2
      src/api/jwt.go
  3. 5 1
      src/api/upload.go

+ 3 - 36
src/api/controller.go

@@ -81,12 +81,8 @@ func ResultJWTWrapper(handle JWTHander, svc *Service) gin.HandlerFunc {
 		if claims["id"] != nil {
 			fmt.Printf("%#v\n", claims)
 			id := claims["id"].(string)
-			name := claims["name"].(string)
-			phone := claims["phone"].(string)
-			parent := claims["parent"].(string)
-			state := int32(claims["state"].(float64))
 
-			usr = &JWTUser{ID: id, Phone: phone, Name: name, Parent: parent, State: state}
+			usr = &JWTUser{ID: id}
 		}
 		var apis = &ApiSession{
 			Svc:  svc,
@@ -135,16 +131,8 @@ func ResultJWTWrapperKey(handle JWTHander, svc *Service, keys []string) gin.Hand
 
 		if claims["id"] != nil {
 			id := claims["id"].(string)
-			phone := claims["phone"].(string)
-			name := claims["name"].(string)
-			parent := claims["parent"].(string)
-			state := int32(claims["state"].(float64))
-			key := ""
-			if claims["key"] != nil {
-				key = claims["key"].(string)
-			}
 
-			usr = &JWTUser{ID: id, Name: name, Phone: phone, Parent: parent, State: state, Key: key}
+			usr = &JWTUser{ID: id}
 		}
 
 		var apis = &ApiSession{
@@ -152,19 +140,6 @@ func ResultJWTWrapperKey(handle JWTHander, svc *Service, keys []string) gin.Hand
 			User: usr,
 		}
 
-		flag := false
-		for _, key := range keys {
-			if usr.Key == key {
-				flag = true
-				break
-			}
-		}
-		if !flag {
-			c.JSON(http.StatusForbidden, NewFailResult("您没有权限"))
-			c.Abort()
-			return
-		}
-
 		data, err := handle(c, apis)
 
 		if err != nil {
@@ -332,15 +307,7 @@ func NewErrorWithCode(desc string, code int32) HTTPError {
 
 // JWTUser jwt登录用户
 type JWTUser struct {
-	ID       string `json:"id"`
-	Parent   string `json:"parent"`
-	Name     string `json:"name"`
-	Phone    string `json:"phone"`
-	Role     string `json:"role"`
-	Perms    string `json:"perms"`
-	State    int32  `json:"state"`
-	Key      string `json:"key"`
-	UserType int    `json:"userType"`
+	ID string `json:"id"`
 }
 
 func UtilQueryMap(c *gin.Context) map[string]interface{} {

+ 2 - 2
src/api/jwt.go

@@ -58,12 +58,12 @@ func NewUitlsJwt(app *conf.AppConf) *UtilsJwt {
 		},
 
 		Authenticator: func(c *gin.Context) (interface{}, error) {
-			return &JWTUser{Phone: "empty"}, nil
+			return &JWTUser{ID: ""}, nil
 		},
 
 		Authorizator: func(data interface{}, _ *gin.Context) bool {
 			u := data.(*JWTUser)
-			return u.State > 0
+			return len(u.ID) > 0
 		},
 
 		LoginResponse: func(c *gin.Context, status int, token string, expire time.Time) {

+ 5 - 1
src/api/upload.go

@@ -22,6 +22,10 @@ func UploadPkg(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	version := c.PostForm("version")
 	name := c.PostForm("name")
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.ID)
+	user, err := GetUserById(apictx, (apictx.User.ID))
+	if err != nil {
+		fmt.Println(err)
+	}
 	file, err := c.FormFile("file")
 	if err != nil {
 		return nil, err
@@ -40,7 +44,7 @@ func UploadPkg(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	versions := &model.Versions{
 		UserId:     userId,
-		UserName:   apictx.User.Name,
+		UserName:   user.LoginName,
 		Name:       name,
 		Url:        fmt.Sprintf("/cr/pkg/%s", file.Filename),
 		Size:       size,