33 lines
605 B
Go
33 lines
605 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"hy2xs-admin/model/bo"
|
|
"hy2xs-admin/model/constant"
|
|
"hy2xs-admin/model/vo"
|
|
"hy2xs-admin/util"
|
|
)
|
|
|
|
func AdminHandler() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
claimsRaw, ok := c.Get("adminClaims")
|
|
if !ok {
|
|
vo.Fail(constant.UnauthorizedError, c)
|
|
c.Abort()
|
|
return
|
|
}
|
|
claims, castOK := claimsRaw.(bo.AccountBo)
|
|
if !castOK {
|
|
vo.Fail(constant.IllegalTokenError, c)
|
|
c.Abort()
|
|
return
|
|
}
|
|
if !util.ArrContain(claims.Roles, "admin") {
|
|
vo.Fail(constant.ForbiddenError, c)
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|