93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
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"
|
|
"time"
|
|
)
|
|
|
|
var Root = "/pet-house"
|
|
var ExcludeBase = "/static"
|
|
var ExcludeBase1 = "/debug"
|
|
var ExcludeBase2 = "/admin"
|
|
|
|
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.PetGoods{},
|
|
&models.SystemConfig{},
|
|
&models.OrderMain{},
|
|
&models.OrderSub{},
|
|
&models.OrderDetail{},
|
|
&models.ServiceCar{},
|
|
&models.CarOrder{},
|
|
&models.ServiceCarUser{},
|
|
&models.ServiceUserMark{},
|
|
&models.ServiceUserMarkRecord{},
|
|
)
|
|
DataInit()
|
|
DataCacheJob()
|
|
}
|
|
func FrontAuth(ctx *context.Context) {
|
|
ctx.Values().Set("reqTime", time.Now())
|
|
if strings.Contains(ctx.Path(), ExcludeBase) {
|
|
ctx.Next()
|
|
return
|
|
}
|
|
if strings.Contains(ctx.Path(), ExcludeBase1) {
|
|
ctx.Next()
|
|
return
|
|
}
|
|
if strings.Contains(ctx.Path(), ExcludeBase2) {
|
|
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.Prefix, PartyFunc: func(index iris.Party) {
|
|
index.Get("/", func(c *context.Context) {
|
|
_, _ = c.WriteString("successful")
|
|
})
|
|
}}
|
|
}
|