🎨 完善部分用户相关接口
This commit is contained in:
@@ -19,9 +19,9 @@ func ClearToken(c *gin.Context) {
|
||||
}
|
||||
|
||||
if net.ParseIP(host) != nil {
|
||||
c.SetCookie("x-token", "", -1, "/", "", false, false)
|
||||
c.SetCookie("app-token", "", -1, "/", "", false, false)
|
||||
} else {
|
||||
c.SetCookie("x-token", "", -1, "/", host, false, false)
|
||||
c.SetCookie("app-token", "", -1, "/", host, false, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,17 +33,17 @@ func SetToken(c *gin.Context, token string, maxAge int) {
|
||||
}
|
||||
|
||||
if net.ParseIP(host) != nil {
|
||||
c.SetCookie("x-token", token, maxAge, "/", "", false, false)
|
||||
c.SetCookie("app-token", token, maxAge, "/", "", false, false)
|
||||
} else {
|
||||
c.SetCookie("x-token", token, maxAge, "/", host, false, false)
|
||||
c.SetCookie("app-token", token, maxAge, "/", host, false, false)
|
||||
}
|
||||
}
|
||||
|
||||
func GetToken(c *gin.Context) string {
|
||||
token := c.Request.Header.Get("x-token")
|
||||
token := c.Request.Header.Get("app-token")
|
||||
if token == "" {
|
||||
j := NewJWT()
|
||||
token, _ = c.Cookie("x-token")
|
||||
token, _ = c.Cookie("app-token")
|
||||
claims, err := j.ParseToken(token)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("重新写入cookie token失败,未能成功解析token,请检查请求头是否存在x-token且claims是否为规定结构")
|
||||
|
Reference in New Issue
Block a user