Merge pull request #163 from alimy/jc/alimy

optimize privApi middleware function
pull/167/head
Michael Li 2 years ago committed by GitHub
commit f683afa540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,24 +9,37 @@ import (
) )
func Priv() gin.HandlerFunc { func Priv() gin.HandlerFunc {
enablePhoneBind := conf.CfgIf("PhoneBind") if conf.CfgIf("PhoneBind") {
return func(c *gin.Context) { return func(c *gin.Context) {
if user, exist := c.Get("USER"); exist { if u, exist := c.Get("USER"); exist {
if userModel, ok := user.(*model.User); ok { if user, ok := u.(*model.User); ok {
if userModel.Status == model.UserStatusNormal { if user.Status == model.UserStatusNormal {
if enablePhoneBind && userModel.Phone == "" { if user.Phone == "" {
response := app.NewResponse(c) response := app.NewResponse(c)
response.ToErrorResponse(errcode.AccountNoPhoneBind) response.ToErrorResponse(errcode.AccountNoPhoneBind)
c.Abort() c.Abort()
return
}
c.Next()
return 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 {
c.Next() c.Next()
return return
} }
} }
response := app.NewResponse(c)
response.ToErrorResponse(errcode.UserHasBeenBanned)
c.Abort()
} }
response := app.NewResponse(c)
response.ToErrorResponse(errcode.UserHasBeenBanned)
c.Abort()
} }
} }

Loading…
Cancel
Save