Initial commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"go.uber.org/zap"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/business/utils"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Root = "/pet-house"
|
||||
var ExcludeBase = "/static"
|
||||
var ExcludeBase1 = "/debug"
|
||||
|
||||
var frontExcludes = [...]string{
|
||||
Root + AuthBase + "/login",
|
||||
}
|
||||
|
||||
func ModuleInit() {
|
||||
utils.WechatInit()
|
||||
_ = database.Instance().AutoMigrate(
|
||||
&models.User{},
|
||||
&models.Pet{},
|
||||
&models.PetBaseInfo{},
|
||||
&models.ServiceAddr{},
|
||||
&models.UserServiceAddr{},
|
||||
&models.Goods{},
|
||||
&models.SystemConfig{},
|
||||
&models.OrderMain{},
|
||||
&models.OrderSub{},
|
||||
&models.OrderDetail{})
|
||||
}
|
||||
|
||||
func FrontAuth(ctx *context.Context) {
|
||||
if strings.Contains(ctx.Path(), ExcludeBase) {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
if strings.Contains(ctx.Path(), ExcludeBase1) {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
frontExcludesStr := strings.Join(frontExcludes[:], ",")
|
||||
if strings.Contains(frontExcludesStr, ctx.Path()) {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
token := ctx.GetHeader("X-Token")
|
||||
uid := ctx.GetHeader("X-U-Id")
|
||||
zap_server.ZAPLOG.Info("frontAuth", zap.Any("path", ctx.Path()), zap.Any("token", token), zap.Any("uid", uid))
|
||||
if len(token) == 0 || len(uid) == 0 {
|
||||
IllegalError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
tokenToUid := GetTokenInfo(token)
|
||||
if len(tokenToUid) == 0 {
|
||||
TokenError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
if uid != tokenToUid {
|
||||
UserError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func (p DefParty) index() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Get("/", func(c *context.Context) {
|
||||
c.WriteString("successful")
|
||||
})
|
||||
}}
|
||||
}
|
||||
Reference in New Issue
Block a user