Use utils.HttpResponse/Abort to replace c.JSON/Abort
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -2,6 +2,7 @@ package middleware
|
||||
|
||||
import (
|
||||
"nixcn-cms/pkgs/authtoken"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -14,12 +15,12 @@ func JWTAuth(required bool) gin.HandlerFunc {
|
||||
authtoken := new(authtoken.Token)
|
||||
uid, err := authtoken.HeaderVerify(auth)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(401, gin.H{"status": err.Error()})
|
||||
utils.HttpAbort(c, 401, "", "unauthorized")
|
||||
return
|
||||
}
|
||||
|
||||
if required == true && uid == "" {
|
||||
c.AbortWithStatusJSON(401, gin.H{"status": "unauthorized"})
|
||||
utils.HttpAbort(c, 401, "", "unauthorized")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user