fix model

This commit is contained in:
wyh 2022-01-13 16:51:18 +08:00
parent d529d4774e
commit 5f387c4402
3 changed files with 8 additions and 13 deletions

View File

@ -1,5 +1,5 @@
package config package config
const ( const (
JwtKey = "3cc2dee3-6471-4b84-9748-e77bb21a5d7f" JwtKey = "3cc2dee3-6471-4b84-9748-e77bb27f"
) )

View File

@ -1,8 +1,6 @@
package handler package handler
import ( import (
"encoding/json"
"io/ioutil"
"strconv" "strconv"
"time" "time"
@ -26,13 +24,8 @@ func userCurrent(c *gin.Context) *model.UserClaims {
func UserToken(c *gin.Context) { func UserToken(c *gin.Context) {
reqbody, _ := ioutil.ReadAll(c.Request.Body) up := &model.User{}
log.WithFields(log.Fields{ if err := c.ShouldBind(up); err != nil {
"func": "UserToken",
}).Infof("%s", string(reqbody))
var up = &model.User{}
if err := json.Unmarshal(reqbody, up); err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"func": "UserToken", "func": "UserToken",
}).Warnf("%s", err) }).Warnf("%s", err)
@ -54,9 +47,10 @@ func UserToken(c *gin.Context) {
}) })
return return
} }
expire := 300
var claims = &model.UserClaims{ var claims = &model.UserClaims{
StandardClaims: jwt.StandardClaims{ 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), Id: strconv.Itoa(result.Uid),
}, },
User: *up, User: *up,
@ -69,7 +63,8 @@ func UserToken(c *gin.Context) {
}).Warnf("%s", err) }).Warnf("%s", err)
} }
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"good": tokenString, "token": tokenString,
"expire": expire,
}) })
} }

View File

@ -1,6 +1,6 @@
@url=http://localhost:80/user @url=http://localhost:80/user
@token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzkwMzIxNjMsImp0aSI6IjEiLCJ1c2VybmFtZSI6Imxpc2kiLCJwYXNzd29yZCI6IjEyMzQ1NiJ9.wjxW6sQev5uaeMSctuajeVlw-L5ZvGvo_4KyaTEeNRU @token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NDIwNjM5NDUsImp0aSI6IjEiLCJ1c2VybmFtZSI6Imxpc2kiLCJwYXNzd29yZCI6IjEyMzQ1NiJ9.2Q_k4-KJjqmkdLEZMVhjiUE4LJ1znUao_Hq0iVswa3I
POST {{url}}/token HTTP/1.1 POST {{url}}/token HTTP/1.1
Content-Type: application/json Content-Type: application/json