diff --git a/config/config.go b/config/config.go index 5b743e5..3196e06 100644 --- a/config/config.go +++ b/config/config.go @@ -1,5 +1,5 @@ package config const ( - JwtKey = "3cc2dee3-6471-4b84-9748-e77bb21a5d7f" + JwtKey = "3cc2dee3-6471-4b84-9748-e77bb27f" ) diff --git a/handler/user-handler.go b/handler/user-handler.go index ea0878b..e8c0d36 100644 --- a/handler/user-handler.go +++ b/handler/user-handler.go @@ -1,8 +1,6 @@ package handler import ( - "encoding/json" - "io/ioutil" "strconv" "time" @@ -26,13 +24,8 @@ func userCurrent(c *gin.Context) *model.UserClaims { func UserToken(c *gin.Context) { - reqbody, _ := ioutil.ReadAll(c.Request.Body) - log.WithFields(log.Fields{ - "func": "UserToken", - }).Infof("%s", string(reqbody)) - - var up = &model.User{} - if err := json.Unmarshal(reqbody, up); err != nil { + up := &model.User{} + if err := c.ShouldBind(up); err != nil { log.WithFields(log.Fields{ "func": "UserToken", }).Warnf("%s", err) @@ -54,9 +47,10 @@ func UserToken(c *gin.Context) { }) return } + expire := 300 var claims = &model.UserClaims{ StandardClaims: jwt.StandardClaims{ - ExpiresAt: time.Now().Add(time.Minute * 5).Unix(), + ExpiresAt: time.Now().Add(time.Second * time.Duration(expire)).Unix(), Id: strconv.Itoa(result.Uid), }, User: *up, @@ -69,7 +63,8 @@ func UserToken(c *gin.Context) { }).Warnf("%s", err) } c.JSON(200, gin.H{ - "good": tokenString, + "token": tokenString, + "expire": expire, }) } diff --git a/token.http b/token.http index e102ee7..46b4e01 100644 --- a/token.http +++ b/token.http @@ -1,6 +1,6 @@ @url=http://localhost:80/user -@token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzkwMzIxNjMsImp0aSI6IjEiLCJ1c2VybmFtZSI6Imxpc2kiLCJwYXNzd29yZCI6IjEyMzQ1NiJ9.wjxW6sQev5uaeMSctuajeVlw-L5ZvGvo_4KyaTEeNRU +@token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NDIwNjM5NDUsImp0aSI6IjEiLCJ1c2VybmFtZSI6Imxpc2kiLCJwYXNzd29yZCI6IjEyMzQ1NiJ9.2Q_k4-KJjqmkdLEZMVhjiUE4LJ1znUao_Hq0iVswa3I POST {{url}}/token HTTP/1.1 Content-Type: application/json