This commit is contained in:
suyl
2021-07-20 16:23:56 +08:00
parent 28485f19ff
commit e04afaed81

View File

@@ -24,10 +24,10 @@ func init() {
func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
var (
cookie *http.Cookie
err error
token string
user *model.User
cookie *http.Cookie
err error
tokenMap map[string]interface{}
user *model.User
)
tokenInfo = &model.TokenInfo{}
//验证token
@@ -43,8 +43,7 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
tokenInfo.Token = cookie.Value
}
globals.SugarLogger.Debugf("checkToken token1: %v", tokenInfo.Token)
if tokenMap := utils.GetKey(tokenInfo.Token).(map[string]interface{}); token == "" {
fmt.Println("111111111111111111111111", tokenMap)
if tokenMap = utils.GetKey(tokenInfo.Token).(map[string]interface{}); tokenMap == nil {
err = fmt.Errorf("token过期或无效请重新登录")
c.JSON(http.StatusOK, &CallBack{
Desc: err.Error(),
@@ -52,8 +51,9 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
})
return nil
}
globals.SugarLogger.Debugf("checkToken token2: %v", token)
if err = json.Unmarshal([]byte(token), &user); err == nil {
globals.SugarLogger.Debugf("checkToken token2: %v", utils.Format4Output(tokenMap, true))
data, _ := json.Marshal(tokenMap)
if err = json.Unmarshal(data, &user); err == nil {
tokenInfo.User = user
} else {
err = fmt.Errorf("token错误请重新登录")