You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/middleware/priv.go

46 lines
1.1 KiB

2 years ago
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/cfg"
"github.com/rocboss/paopao-ce/pkg/errcode"
2 years ago
)
func Priv() gin.HandlerFunc {
if cfg.If("PhoneBind") {
return func(c *gin.Context) {
if u, exist := c.Get("USER"); exist {
if user, ok := u.(*model.User); ok {
if user.Status == model.UserStatusNormal {
if user.Phone == "" {
response := app.NewResponse(c)
response.ToErrorResponse(errcode.AccountNoPhoneBind)
c.Abort()
return
}
c.Next()
2 years ago
return
}
}
}
response := app.NewResponse(c)
response.ToErrorResponse(errcode.UserHasBeenBanned)
c.Abort()
}
} else {
return func(c *gin.Context) {
if u, exist := c.Get("USER"); exist {
if user, ok := u.(*model.User); ok && user.Status == model.UserStatusNormal {
2 years ago
c.Next()
return
}
}
response := app.NewResponse(c)
response.ToErrorResponse(errcode.UserHasBeenBanned)
c.Abort()
2 years ago
}
}
}