审查视图

pkg/port/beego/middlewares/check_font_token.go 920 字节
庄敏学 authored
1 2 3
package middlewares

import (
tangxvhui authored
4 5
	"strings"
庄敏学 authored
6 7 8 9 10 11 12
	"github.com/beego/beego/v2/server/web/context"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)

func CheckFontToken() func(ctx *context.Context) {
	return func(ctx *context.Context) {
tangxvhui authored
13 14 15 16 17 18 19 20 21 22 23
		// adminToken := ctx.Input.Header("x-font-token")
		// Bearer authorization_token
		adminToken := ctx.Input.Header("Authorization")
		//以一个空格" ",做切分
		strList := strings.Split(adminToken, " ")
		if len(strList) > 1 {
			adminToken = strList[1]
		}
		if len(strList) == 1 {
			adminToken = strList[0]
		}
庄敏学 authored
24 25 26 27 28 29 30 31 32 33 34 35
		userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken)
		if err != nil || userAuth.UserId <= 0 {
			forbidden(ctx)
			return
		}
		if userAuth.PlatformId != constant.PLATFORM_FONT_ID {
			forbidden(ctx)
			return
		}
		ctx.Input.SetData(domain.UserAuth{}, userAuth)
	}
}