增加excel模板配置,增加前端导出工具。token迁移至cookie x-token且保留header x-token 两者兼容。

This commit is contained in:
piexlMax
2023-12-30 19:57:36 +08:00
parent 5ea8947fc9
commit cd5b60c8cc
23 changed files with 1275 additions and 38 deletions

View File

@@ -3,6 +3,7 @@ package middleware
import (
"errors"
"github.com/golang-jwt/jwt/v4"
"net"
"strconv"
"time"
@@ -22,7 +23,10 @@ var jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService
func JWTAuth() gin.HandlerFunc {
return func(c *gin.Context) {
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
token := c.Request.Header.Get("x-token")
token, _ := c.Cookie("x-token")
if token == "" {
token = c.Request.Header.Get("x-token")
}
if token == "" {
response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)
c.Abort()
@@ -62,6 +66,12 @@ func JWTAuth() gin.HandlerFunc {
newClaims, _ := j.ParseToken(newToken)
c.Header("new-token", newToken)
c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt.Unix(), 10))
// 增加cookie x-token
host, _, err := net.SplitHostPort(c.Request.Host)
if err != nil {
host = c.Request.Host
}
c.SetCookie("x-token", newToken, int(dr.Seconds()), "/", host, false, true)
if global.GVA_CONFIG.System.UseMultipoint {
RedisJwtToken, err := jwtService.GetRedisJWT(newClaims.Username)
if err != nil {