forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"stat/common/enum/consts"
|
||||
"stat/common/utils"
|
||||
"stat/middleware/define"
|
||||
"stat/models/adminMod"
|
||||
"stat/service/agentSer"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// gin 验证中间件
|
||||
|
||||
var (
|
||||
// 白名单,不需要验证token的api
|
||||
whiteList = []string{
|
||||
"/swagger/*",
|
||||
"/swagger",
|
||||
"/favicon.ico",
|
||||
"/api/stat/admin/login",
|
||||
"/api/stat/admin/verify",
|
||||
"/api/stat/agent/imgVerify",
|
||||
"/api/stat/agent/login",
|
||||
"/api/stat/agent/verify",
|
||||
"/api/stat/billserver/callback",
|
||||
"/api/stat/version/bottonclick",
|
||||
"/api/stat/version/bottonlist",
|
||||
"/api/stat/version/crossbottonclick",
|
||||
"/api/stat/share/list",
|
||||
"/api/stat/ads/get",
|
||||
"/api/stat/ads/click",
|
||||
"/api/stat/commodity/info",
|
||||
"/api/stat/commodity/rechargeType",
|
||||
"/api/stat/commodity/buy",
|
||||
"/api/stat/commodity/order",
|
||||
"/api/stat/version/app",
|
||||
"/api/stat/userInvite/userlist",
|
||||
"/api/stat/userInvite/incomelist",
|
||||
"/api/stat/userInvite/district",
|
||||
"/api/stat/user/districtcode",
|
||||
"/api/stat/callback/rchg/bill",
|
||||
"/api/stat/blocDailyStatTotal/list",
|
||||
"/api/stat/adminbloc/login",
|
||||
"/api/stat/channelCodeStat/list",
|
||||
"/api/stat/loufeng/sync",
|
||||
"/api/stat/districtMinuteStat/list",
|
||||
"/api/stat/loufeng/uploadImg",
|
||||
"/api/stat/loufeng/complaint", //楼凤投诉
|
||||
"/api/stat/model/sync", //嫩模同步
|
||||
"/api/stat/novel/sync",
|
||||
"/api/stat/novel/audio/sync",
|
||||
"/api/stat/file/upload",
|
||||
"/api/stat/model/syncBroker",
|
||||
"/api/stat/loufeng/complaint",
|
||||
"/api/stat/loufeng/queryComplaint",
|
||||
"/api/stat/openinstall/auth",
|
||||
"/api/stat/openinstall/total",
|
||||
"/api/stat/openinstall/info",
|
||||
"/api/stat/openinstall/growth",
|
||||
"/api/stat/openinstall/allstat",
|
||||
"/api/stat/openinstall/active",
|
||||
"/api/stat/activity/h5/info",
|
||||
"/api/stat/activity/h5/giftinfo",
|
||||
"/api/stat/activity/h5/draw",
|
||||
"/api/stat/landPageConfig/getByType",
|
||||
"/api/stat/media/m3u8",
|
||||
"/api/stat/media/enkey",
|
||||
"/api/stat/version/h5/config",
|
||||
"/api/stat/version/channel/newLink",
|
||||
"/api/stat/inner/botStatList",
|
||||
"/api/stat/inner/appList",
|
||||
"/api/stat/inner/appDownload",
|
||||
"/api/stat/inner/botMonthStat",
|
||||
"/api/stat/inner/sendTgMessage",
|
||||
"/api/stat/activity/visit",
|
||||
"/api/stat/landPage/summary/downTotal/list",
|
||||
"/api/stat/web/apps/get",
|
||||
"/api/stat/web/apps/click",
|
||||
"/api/stat/inner/recharge/list",
|
||||
"/api/stat/inner/rechargebotcmd/list",
|
||||
"/api/stat/daily-stat/jtspV2",
|
||||
"/api/stat/daily-stat/hour",
|
||||
"/api/stat/daily-stat/rank",
|
||||
"/api/stat/daily-stat/total",
|
||||
}
|
||||
)
|
||||
|
||||
func Auth(ctx *gin.Context) {
|
||||
for _, w := range whiteList {
|
||||
if strings.HasPrefix(ctx.Request.URL.Path, w) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
authToken := func() (int, error) {
|
||||
checkToken := ctx.Request.Header.Get("Authorization")
|
||||
if checkToken == "" {
|
||||
return http.StatusBadRequest, define.NoToken
|
||||
}
|
||||
claims, err := define.ParseToken(checkToken)
|
||||
if err != nil {
|
||||
return http.StatusMovedPermanently, define.RepeatLogin
|
||||
}
|
||||
|
||||
if claims.Type == define.Admin {
|
||||
has, err := adminMod.CheckToken(ctx, checkToken)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
if !has {
|
||||
return http.StatusMovedPermanently, define.RepeatLogin
|
||||
}
|
||||
} else if claims.Type == define.Channel {
|
||||
//fmt.Println("", claims.Type, claims.ShowMagic)
|
||||
if claims.ShowMagic > "3" {
|
||||
return consts.ShowMagic, nil
|
||||
}
|
||||
err := agentSer.CheckToken(ctx, claims.Name, checkToken)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
}
|
||||
ctx.Set(utils.AdminAccountKey, claims.Name)
|
||||
ctx.Set(utils.AccountTypeKey, claims.Type)
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
statusCode, err := authToken()
|
||||
if err != nil || statusCode != 0 {
|
||||
if statusCode == consts.ShowMagic {
|
||||
ctx.AbortWithStatusJSON(200, gin.H{})
|
||||
} else {
|
||||
ctx.AbortWithStatusJSON(statusCode, gin.H{"msg": fmt.Sprintf("%+v", err)})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user