|
|
@ -17,7 +17,7 @@ func AuthMiddleWare() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
|
|
// 验证token
|
|
|
|
// 验证token
|
|
|
|
if tokenString == "" || !strings.HasPrefix(tokenString, "Bearer ") {
|
|
|
|
if tokenString == "" || !strings.HasPrefix(tokenString, "Bearer ") {
|
|
|
|
c.JSON(http.StatusUnauthorized, gin.H{
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"message": "请求未授权",
|
|
|
|
"message": "请求未授权",
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -29,7 +29,7 @@ func AuthMiddleWare() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
|
|
token, claims, err := common.ParseToken(tokenString)
|
|
|
|
token, claims, err := common.ParseToken(tokenString)
|
|
|
|
if err != nil || !token.Valid {
|
|
|
|
if err != nil || !token.Valid {
|
|
|
|
c.JSON(http.StatusUnauthorized, gin.H{
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"message": "请求未授权",
|
|
|
|
"message": "请求未授权",
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -44,7 +44,7 @@ func AuthMiddleWare() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
|
|
// 用户不存在
|
|
|
|
// 用户不存在
|
|
|
|
if user.ID == 0 {
|
|
|
|
if user.ID == 0 {
|
|
|
|
c.JSON(http.StatusUnauthorized, gin.H{
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"code": http.StatusUnauthorized,
|
|
|
|
"message": "请求未授权",
|
|
|
|
"message": "请求未授权",
|
|
|
|
})
|
|
|
|
})
|
|
|
|