增加获取路由树功能
This commit is contained in:
@@ -5,19 +5,16 @@ import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"net/http"
|
||||
"main/controller/servers"
|
||||
"time"
|
||||
)
|
||||
|
||||
func JWTAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localSstorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
|
||||
token := c.Request.Header.Get("x-token")
|
||||
if token == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"msg": "未登录或非法访问",
|
||||
"data": gin.H{},
|
||||
})
|
||||
servers.ReportFormat(c, false, "未登录或非法访问", gin.H{})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -26,17 +23,11 @@ func JWTAuth() gin.HandlerFunc {
|
||||
claims, err := j.ParseToken(token)
|
||||
if err != nil {
|
||||
if err == TokenExpired {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"msg": "授权已过期",
|
||||
})
|
||||
servers.ReportFormat(c, false, "授权已过期", gin.H{})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"msg": err.Error(),
|
||||
})
|
||||
servers.ReportFormat(c, false, err.Error(), gin.H{})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -53,13 +44,14 @@ var (
|
||||
TokenNotValidYet error = errors.New("Token not active yet")
|
||||
TokenMalformed error = errors.New("That's not even a token")
|
||||
TokenInvalid error = errors.New("Couldn't handle this token:")
|
||||
SignKey string = "newtrekWang"
|
||||
SignKey string = "qmPlus"
|
||||
)
|
||||
|
||||
type CustomClaims struct {
|
||||
UUID uuid.UUID
|
||||
ID uint
|
||||
AuthorityID uint
|
||||
NickName string
|
||||
AuthorityId float64
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user