mirror of https://github.com/rocboss/paopao-ce
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.
50 lines
1.2 KiB
50 lines
1.2 KiB
// Copyright 2022 ROC. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package chain
|
|
|
|
import (
|
|
"github.com/alimy/cfg"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
"github.com/rocboss/paopao-ce/pkg/app"
|
|
"github.com/rocboss/paopao-ce/pkg/errcode"
|
|
)
|
|
|
|
func Priv() gin.HandlerFunc {
|
|
if cfg.If("PhoneBind") {
|
|
return func(c *gin.Context) {
|
|
if u, exist := c.Get("USER"); exist {
|
|
if user, ok := u.(*core.User); ok {
|
|
if user.Status == core.UserStatusNormal {
|
|
if user.Phone == "" {
|
|
response := app.NewResponse(c)
|
|
response.ToErrorResponse(errcode.AccountNoPhoneBind)
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Next()
|
|
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.(*core.User); ok && user.Status == core.UserStatusNormal {
|
|
c.Next()
|
|
return
|
|
}
|
|
}
|
|
response := app.NewResponse(c)
|
|
response.ToErrorResponse(errcode.UserHasBeenBanned)
|
|
c.Abort()
|
|
}
|
|
}
|
|
}
|