Yi 1 рік тому
батько
коміт
6aeb3a3a65
4 змінених файлів з 14 додано та 9 видалено
  1. 1 4
      http/handle/api/user.go
  2. 0 4
      http/handle/restful/user.go
  3. 0 1
      middleware/jwt/jwt.go
  4. 13 0
      pkg/app/response.go

+ 1 - 4
http/handle/api/user.go

@@ -45,9 +45,6 @@ func Auth(c *gin.Context) {
 	appG := app.Gin{C: c}
 	var reqInfo auth
 	err := c.BindJSON(&reqInfo)
-	//c.Request.ParseForm()
-	//reqInfo.Username = c.PostForm("username")
-	//reqInfo.Password = c.PostForm("pwd")
 
 	valid := validation.Validation{}
 	valid.MaxSize(reqInfo.Username, 100, "username").Message("最长为100字符")
@@ -148,7 +145,7 @@ func UserLogout(c *gin.Context) {
 // @Router /authdata/userinfo  [GET]
 func GetUserinfo(c *gin.Context) {
 	appG := app.Gin{C: c}
-	data := restful.GetUserInfo(c.Param("jwt_username"))
+	data := restful.GetUserInfo(appG.Get("jwt_username"))
 	appG.Response(http.StatusOK, e.SUCCESS, data)
 }
 

+ 0 - 4
http/handle/restful/user.go

@@ -1,8 +1,6 @@
 package restful
 
 import (
-	"fmt"
-
 	"github.com/pkg/errors"
 )
 
@@ -44,8 +42,6 @@ func CheckUser(username, password string) (bool, error) {
 }
 
 func GetUserInfo(username string) map[string]interface{} {
-
-	fmt.Println("=====GetUserInfo=====", username)
 	valuesMap, err := Engine.SQL("SELECT * FROM  `user` WHERE `username` = ? and `enable` >0 ", username).Query().List()
 
 	if err != nil {

+ 0 - 1
middleware/jwt/jwt.go

@@ -35,7 +35,6 @@ func JWT() gin.HandlerFunc {
 				}
 			}
 		}
-
 		if code != e.SUCCESS {
 			c.JSON(e.SUCCESS, gin.H{
 				"code": code,

+ 13 - 0
pkg/app/response.go

@@ -29,3 +29,16 @@ func (g *Gin) ResponseEq(httpCode, errCode int, errorNo int, data interface{}) {
 	})
 	return
 }
+
+func (g *Gin) Get(key string) string {
+	if str, ok := g.C.Get(key); !ok {
+		return ""
+	} else {
+		switch str.(type) {
+		case string:
+			return str.(string)
+		}
+	}
+
+	return ""
+}