大改jwt

This commit is contained in:
eson 2023-07-26 12:15:15 +08:00
parent 4c104b56ae
commit 01cc7da3b4
64 changed files with 194 additions and 88 deletions

View File

@ -13,7 +13,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
{{if .HasRequest}}var req types.{{.RequestType}}
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func RedirectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestRedirect
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func AcceptCookieHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserEmailRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestEmailRegister
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserGoogleLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestGoogleLogin
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestUserLogin
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetCanteenDetailReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.SaveCanteenTypeProductReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestAddAddress
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserContactServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestContactService
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserOderDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestOrderId
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserOrderCancelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserOrderCancelReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserOrderListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestBasicInfoForm
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UserStatusConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetPickupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetPickupListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func SupplementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SupplementReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func TakeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TakeReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetOrderDetailReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetOrderInvoiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetOrderInvoiceReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func DesignGatherHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DesignGatherReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetFittingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetFittingByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetLastProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetLightByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetLightByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetModelByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetModelByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetPriceByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetPriceByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductDesignReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductInfoReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetRecommandProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetRenderDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetRenderDesignReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetRenderSettingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetRenderSettingByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetSizeByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetSizeByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetSuccessRecommandReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetTagProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func GetTemplateByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetTemplateByPidReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func HomePageRecommendProductListHandler(svcCtx *svc.ServiceContext) http.Handle
return func(w http.ResponseWriter, r *http.Request) {
var req types.HomePageRecommendProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func OtherProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.OtherProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func SaveDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SaveDesignReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestReadImages
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestToUnity
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CartAddReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CartDeleteReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CartListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CartOrderDetailReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChangeOrderMethodReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateOrderReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UploadFileFrontendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestUploadFileFrontend
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UploadQrcodeReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func UploadUpFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestUpFile
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

View File

@ -15,7 +15,7 @@ func WebSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestWebSet
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
userinfo, err := basic.RequestParse(w, r, svcCtx.SharedState, &req)
if err != nil {
return
}

59
utils/auth/jwt_token.go Normal file
View File

@ -0,0 +1,59 @@
package auth
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
)
func ParseJwtTokenHeader[T any](r *http.Request) (string, *T, error) {
AuthKey := r.Header.Get("Authorization")
if AuthKey == "" {
return "", nil, nil
}
if len(AuthKey) <= 15 {
return "", nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
}
AuthKey = AuthKey[7:]
parts := strings.Split(AuthKey, ".")
if len(parts) != 3 {
return "", nil, fmt.Errorf("Invalid JWT token")
}
payload, err := base64.URLEncoding.DecodeString(parts[1])
if err != nil {
return "", nil, fmt.Errorf("Error unmarshalling JWT DecodeString: %s", err.Error())
}
var p T
err = json.Unmarshal(payload, &p)
if err != nil {
return "", nil, fmt.Errorf("Error unmarshalling JWT payload: %s", err)
}
return AuthKey, &p, nil
// token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
// // 检查签名方法是否为 HS256
// if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
// return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
// }
// // 返回用于验证签名的密钥
// return []byte(svcCtx.Config.Auth.AccessSecret), nil
// })
// if err != nil {
// return nil, errors.New(fmt.Sprint("Error parsing token:", err))
// }
// // 验证成功返回
// if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
// return claims, nil
// }
// return nil, errors.New(fmt.Sprint("Invalid token", err))
}

View File

@ -11,7 +11,7 @@ import (
"github.com/golang-jwt/jwt"
)
func ParseJwtTokenUint64Secret(r *http.Request, AccessSecret uint64) (jwt.MapClaims, error) {
func ParseJwtTokenUint64SecretByRequest(r *http.Request, AccessSecret uint64) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if AuthKey == "" {
return nil, nil
@ -46,6 +46,32 @@ func ParseJwtTokenUint64Secret(r *http.Request, AccessSecret uint64) (jwt.MapCla
return nil, errors.New(fmt.Sprint("Invalid token", err))
}
func ParseJwtTokenUint64Secret(AuthKey string, AccessSecret uint64) (jwt.MapClaims, error) {
// Convert uint64 to []byte
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, AccessSecret)
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
// 检查签名方法是否为 HS256
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return key, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
}
// 验证成功返回
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
return claims, nil
}
return nil, errors.New(fmt.Sprint("Invalid token", err))
}
// ValidateEmail checks if the provided string is a valid email address.
func ValidateEmail(email string) bool {
_, err := mail.ParseAddress(email)

View File

@ -2,6 +2,7 @@ package basic
import (
"errors"
"fusenapi/fsm"
"fusenapi/utils/auth"
"net/http"
"reflect"
@ -11,6 +12,8 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)
var DefaultJwtSecret uint64 = 21321321321
type IJWTParse interface {
ParseJwtToken(r *http.Request) (jwt.MapClaims, error)
}
@ -48,48 +51,66 @@ func NormalAfterLogic(w http.ResponseWriter, r *http.Request, resp *Response) {
}
}
func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx IJWTParse, LogicRequest any) (userinfo *auth.UserInfo, err error) {
func RequestParse(w http.ResponseWriter, r *http.Request, state *fsm.StateCluster, LogicRequest any) (*auth.UserInfo, error) {
// 解析JWT token,并对空用户进行判断
claims, err := svcCtx.ParseJwtToken(r)
// auth.ParseJwtTokenUint64Secret()
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r)
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &Response{
Code: 401, // 返回401状态码,表示未授权
Message: "unauthorized", // 返回未授权信息
})
logx.Info("unauthorized:", err.Error()) // 记录错误日志
return
logx.Error(err)
return nil, err
}
if claims != nil {
// 从token中获取对应的用户信息
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
var secret uint64 = 0
if info.IsUser() {
us, err := state.GetUserState(info.UserId)
if err != nil {
logx.Error(err)
return nil, err
}
secret = us.PwdHash
} else if info.IsGuest() {
secret = DefaultJwtSecret
}
var userinfo *auth.UserInfo
if secret != 0 {
claims, err := auth.ParseJwtTokenUint64Secret(token, secret)
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &Response{
Code: 401,
Message: "unauthorized",
Code: 401, // 返回401状态码,表示未授权
Message: "unauthorized", // 返回未授权信息
})
logx.Info("unauthorized:", err.Error())
return
logx.Info("unauthorized:", err.Error()) // 记录错误日志
return nil, err
}
if claims != nil {
// 从token中获取对应的用户信息
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &Response{
Code: 401,
Message: "unauthorized",
})
logx.Info("unauthorized:", err.Error())
return nil, err
}
} else {
// 如果claims为nil,则认为用户身份为白板用户
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
} else {
// 如果claims为nil,则认为用户身份为白板用户
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
// var req types.RequestGoogleLogin
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据
if err = httpx.Parse(r, LogicRequest); err != nil {
httpx.OkJsonCtx(r.Context(), w, &Response{
Code: 510,
Message: "parameter error",
})
logx.Info(err)
return
logx.Error(err)
return nil, err
}
return userinfo, err