This commit is contained in:
jiayuqi7813
2022-05-21 23:29:23 +08:00
parent b8859af6d8
commit 7cb171bc90
83 changed files with 1687 additions and 0 deletions

38
api/admin/auth.go Normal file
View File

@@ -0,0 +1,38 @@
package admin
import (
"github.com/gin-gonic/gin"
."main.go/type"
"main.go/api"
)
// AuthRequired 用于管理员权限控制的中间件
func AuthRequired()gin.HandlerFunc {
return func(c *gin.Context) {
session, err := api.Store.Get(c.Request, "SNCTFSESSID")
if err != nil {
c.JSON(200, gin.H{"code": 400, "msg": "Get SNCTFSESSID error"})
c.Abort()
return
}
user, ok := session.Values["user"].(User)
if !ok {
c.JSON(200, gin.H{"code": 400, "msg": "No session"})
c.Abort()
return
}
if user.Role != 1 {
c.JSON(200, gin.H{"code": 400, "msg": "Unauthorized access!"})
c.Abort()
return
}
c.Next()
}
}