mirror of https://github.com/rocboss/paopao-ce
parent
315060233b
commit
c1ed0dfb4a
@ -0,0 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rocboss/paopao-ce/internal/model"
|
||||
"github.com/rocboss/paopao-ce/pkg/app"
|
||||
"github.com/rocboss/paopao-ce/pkg/errcode"
|
||||
)
|
||||
|
||||
func Admin() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if user, exist := c.Get("USER"); exist {
|
||||
if userModel, ok := user.(*model.User); ok {
|
||||
if userModel.Status == model.UserStatusNormal && userModel.IsAdmin {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response := app.NewResponse(c)
|
||||
response.ToErrorResponse(errcode.NoAdminPermission)
|
||||
c.Abort()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue