feat: 引入签名认证、加密工具包及大量goctl代码生成模板,并更新API、Admin和Node服务逻辑。
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
@@ -14,5 +16,11 @@ type Config struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
CoreRpc zrpc.RpcClientConf
|
||||
CoreRpc zrpc.RpcClientConf
|
||||
CacheRedis redis.RedisConf
|
||||
AppSignature signature.SignatureConf
|
||||
Security struct {
|
||||
Enable bool
|
||||
SecuritySecret string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ResetPasswordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||
err := l.ResetPassword(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
resp, err := l.ResetPassword(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserLoginReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewUserLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserLogin(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func UserRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserRegisterReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewUserRegisterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserRegister(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetAnnouncementListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetAnnouncementListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAnnouncementList()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetAvailablePaymentMethodsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetAvailablePaymentMethodsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAvailablePaymentMethods()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetDocumentDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DocumentDetailReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := common.NewGetDocumentDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetDocumentDetail(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetDocumentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetDocumentListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetDocumentList()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetGlobalConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetGlobalConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetGlobalConfig()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetSubscribeGroupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetSubscribeGroupListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetSubscribeGroupList()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetSubscribeListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewGetSubscribeListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetSubscribeList()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewHealthLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Health()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func SendEmailCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.SendEmailCodeReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := common.NewSendEmailCodeLogic(r.Context(), svcCtx)
|
||||
err := l.SendEmailCode(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func CloseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CloseOrderReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewCloseOrderLogic(r.Context(), svcCtx)
|
||||
err := l.CloseOrder(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateOrderReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewCreateOrderLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateOrder(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OrderDetailReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewGetOrderDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetOrderDetail(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reset_password",
|
||||
Path: "/reset",
|
||||
Handler: auth.ResetPasswordHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func CreateTicketFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateTicketFollowReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := ticket.NewCreateTicketFollowLogic(r.Context(), svcCtx)
|
||||
err := l.CreateTicketFollow(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func CreateTicketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateTicketReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := ticket.NewCreateTicketLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateTicket(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetTicketDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.TicketDetailReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := ticket.NewGetTicketDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetTicketDetail(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := user.NewGetUserInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserInfo()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func GetUserSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := user.NewGetUserSubscribeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserSubscribe()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,19 @@ import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||
)
|
||||
|
||||
func UpdateUserPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdatePasswordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err := result.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewUpdateUserPasswordLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateUserPassword(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) error {
|
||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) (resp *types.LoginResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.UserLoginReq) (resp *types.AuthResp, err error) {
|
||||
func (l *UserLoginLogic) UserLogin(req *types.UserLoginReq) (resp *types.LoginResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterReq) (resp *types.AuthResp, err error) {
|
||||
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterReq) (resp *types.LoginResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,17 +27,7 @@ func NewHealthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthLogi
|
||||
}
|
||||
|
||||
func (l *HealthLogic) Health() (resp *types.HealthResp, err error) {
|
||||
// 调用 RPC 进行 Ping 测试,这能触发全链路追踪 (API -> RPC)
|
||||
rpcResp, err := l.svcCtx.CoreRpc.Ping(l.ctx, &core.Empty{})
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
status := "ok"
|
||||
if err != nil {
|
||||
status = "rpc_error: " + err.Error()
|
||||
} else if rpcResp.Msg != "" {
|
||||
status = rpcResp.Msg
|
||||
}
|
||||
|
||||
return &types.HealthResp{
|
||||
Status: status,
|
||||
}, nil
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/cryptox"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
type DecryptMiddleware struct {
|
||||
conf config.Config
|
||||
}
|
||||
|
||||
func NewDecryptMiddleware(c config.Config) *DecryptMiddleware {
|
||||
return &DecryptMiddleware{conf: c}
|
||||
}
|
||||
|
||||
func (m *DecryptMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !m.conf.Security.Enable {
|
||||
next(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Header.Get("Login-Type") != "device" {
|
||||
next(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
secret := m.conf.Security.SecuritySecret
|
||||
rw := newEncryptResponseWriter(w, secret)
|
||||
|
||||
// 解密 GET query
|
||||
query := r.URL.Query()
|
||||
dataStr := query.Get("data")
|
||||
timeStr := query.Get("time")
|
||||
if dataStr != "" && timeStr != "" {
|
||||
if plain, err := cryptox.Decrypt(dataStr, secret, timeStr); err == nil {
|
||||
params := map[string]interface{}{}
|
||||
if json.Unmarshal(plain, ¶ms) == nil {
|
||||
for k, v := range params {
|
||||
query.Set(k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
query.Del("data")
|
||||
query.Del("time")
|
||||
rawQuery := query.Encode()
|
||||
if strings.Contains(r.RequestURI, "?") {
|
||||
r.RequestURI = r.RequestURI[:strings.Index(r.RequestURI, "?")] + "?" + rawQuery
|
||||
}
|
||||
r.URL.RawQuery = rawQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 解密 POST body
|
||||
if r.Body != nil {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil || len(body) == 0 {
|
||||
// body 为空或读取失败,直接放行
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
next(rw, r)
|
||||
rw.flush()
|
||||
return
|
||||
}
|
||||
|
||||
var envelope struct {
|
||||
Data string `json:"data"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &envelope); err != nil || envelope.Data == "" {
|
||||
httpx.Error(w, xerr.NewErrCode(xerr.DecryptFailed))
|
||||
return
|
||||
}
|
||||
|
||||
plain, err := cryptox.Decrypt(envelope.Data, secret, envelope.Time)
|
||||
if err != nil {
|
||||
httpx.Error(w, xerr.NewErrCode(xerr.DecryptFailed))
|
||||
return
|
||||
}
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(plain))
|
||||
}
|
||||
|
||||
next(rw, r)
|
||||
rw.flush()
|
||||
}
|
||||
}
|
||||
|
||||
// encryptResponseWriter 拦截响应,加密 data 字段
|
||||
type encryptResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
body *bytes.Buffer
|
||||
secret string
|
||||
status int
|
||||
}
|
||||
|
||||
func newEncryptResponseWriter(w http.ResponseWriter, secret string) *encryptResponseWriter {
|
||||
return &encryptResponseWriter{
|
||||
ResponseWriter: w,
|
||||
body: new(bytes.Buffer),
|
||||
secret: secret,
|
||||
status: http.StatusOK,
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *encryptResponseWriter) WriteHeader(code int) {
|
||||
rw.status = code
|
||||
}
|
||||
|
||||
func (rw *encryptResponseWriter) Write(data []byte) (int, error) {
|
||||
return rw.body.Write(data)
|
||||
}
|
||||
|
||||
func (rw *encryptResponseWriter) WriteString(s string) (int, error) {
|
||||
return rw.body.WriteString(s)
|
||||
}
|
||||
|
||||
func (rw *encryptResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return rw.ResponseWriter.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
func (rw *encryptResponseWriter) flush() {
|
||||
buf := rw.body.Bytes()
|
||||
out := buf
|
||||
|
||||
// 尝试加密 data 字段
|
||||
params := map[string]interface{}{}
|
||||
if err := json.Unmarshal(buf, ¶ms); err == nil {
|
||||
if data := params["data"]; data != nil {
|
||||
var jsonData []byte
|
||||
if str, ok := data.(string); ok {
|
||||
jsonData = []byte(str)
|
||||
} else {
|
||||
jsonData, _ = json.Marshal(data)
|
||||
}
|
||||
if dataB64, nonce, err := cryptox.Encrypt(jsonData, rw.secret); err == nil {
|
||||
params["data"] = map[string]interface{}{
|
||||
"data": dataB64,
|
||||
"time": nonce,
|
||||
}
|
||||
if enc, err := json.Marshal(params); err == nil {
|
||||
out = enc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rw.ResponseWriter.WriteHeader(rw.status)
|
||||
rw.ResponseWriter.Write(out)
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
type SignatureMiddleware struct {
|
||||
conf config.Config
|
||||
validator *signature.Validator
|
||||
}
|
||||
|
||||
func NewSignatureMiddleware(c config.Config, store signature.NonceStore) *SignatureMiddleware {
|
||||
return &SignatureMiddleware{
|
||||
conf: c,
|
||||
validator: signature.NewValidator(c.AppSignature, store),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SignatureMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
appId := r.Header.Get("X-App-Id")
|
||||
// X-App-Id 为空,提示非法访问
|
||||
if appId == "" {
|
||||
httpx.Error(w, xerr.NewErrCode(xerr.InvalidAccess))
|
||||
return
|
||||
}
|
||||
|
||||
// SkipPrefixes 白名单
|
||||
for _, prefix := range m.conf.AppSignature.SkipPrefixes {
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
next(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
timestamp := r.Header.Get("X-Timestamp")
|
||||
nonce := r.Header.Get("X-Nonce")
|
||||
sig := r.Header.Get("X-Signature")
|
||||
|
||||
if timestamp == "" || nonce == "" || sig == "" {
|
||||
httpx.Error(w, xerr.NewErrCode(xerr.SignatureMissing))
|
||||
return
|
||||
}
|
||||
|
||||
// 读取 body(签名对原始 body bytes 计算)
|
||||
var bodyBytes []byte
|
||||
if r.Body != nil {
|
||||
bodyBytes, _ = io.ReadAll(r.Body)
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
}
|
||||
|
||||
sts := signature.BuildStringToSign(r.Method, r.URL.Path, r.URL.RawQuery, bodyBytes, appId, timestamp, nonce)
|
||||
|
||||
if err := m.validator.Validate(r.Context(), appId, timestamp, nonce, sig, sts); err != nil {
|
||||
code := mapSignatureErr(err)
|
||||
httpx.Error(w, xerr.NewErrCode(code))
|
||||
return
|
||||
}
|
||||
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func mapSignatureErr(err error) int {
|
||||
switch err {
|
||||
case signature.ErrSignatureMissing:
|
||||
return xerr.SignatureMissing
|
||||
case signature.ErrSignatureExpired:
|
||||
return xerr.SignatureExpired
|
||||
case signature.ErrSignatureReplay:
|
||||
return xerr.SignatureReplay
|
||||
default:
|
||||
return xerr.SignatureInvalid
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,28 @@ package svc
|
||||
|
||||
import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/coreclient"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/middleware"
|
||||
coreClient "github.com/zero-ppanel/zero-ppanel/apps/rpc/core/coreclient"
|
||||
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
CoreRpc coreClient.Core
|
||||
Config config.Config
|
||||
CoreRpc coreClient.Core
|
||||
SignatureMiddleware *middleware.SignatureMiddleware
|
||||
DecryptMiddleware *middleware.DecryptMiddleware
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
rds := redis.MustNewRedis(c.CacheRedis)
|
||||
nonceStore := signature.NewRedisNonceStore(rds)
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
CoreRpc: coreClient.NewCore(zrpc.MustNewClient(c.CoreRpc)),
|
||||
Config: c,
|
||||
CoreRpc: coreClient.NewCore(zrpc.MustNewClient(c.CoreRpc)),
|
||||
SignatureMiddleware: middleware.NewSignatureMiddleware(c, nonceStore),
|
||||
DecryptMiddleware: middleware.NewDecryptMiddleware(c),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,6 @@ type AnnouncementResp struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
type AuthResp struct {
|
||||
Token string `json:"token"`
|
||||
Expire int64 `json:"expire"`
|
||||
}
|
||||
|
||||
type CloseOrderReq struct {
|
||||
OrderNo string `path:"order_no"`
|
||||
}
|
||||
@@ -63,6 +58,10 @@ type HealthResp struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type LoginResp struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type OrderDetailReq struct {
|
||||
OrderNo string `path:"order_no"`
|
||||
}
|
||||
@@ -84,9 +83,14 @@ type PaymentMethodResp struct {
|
||||
}
|
||||
|
||||
type ResetPasswordReq struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Code string `json:"code"`
|
||||
Identifier string `json:"identifier"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
Code string `json:"code,optional"`
|
||||
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||
UserAgent string `header:"User-Agent,optional"`
|
||||
LoginType string `header:"Login-Type,optional"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
}
|
||||
|
||||
type SendEmailCodeReq struct {
|
||||
@@ -132,15 +136,25 @@ type UserInfoResp struct {
|
||||
}
|
||||
|
||||
type UserLoginReq struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Identifier string `json:"identifier"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||
UserAgent string `header:"User-Agent,optional"`
|
||||
LoginType string `header:"Login-Type,optional"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
}
|
||||
|
||||
type UserRegisterReq struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Code string `json:"code"`
|
||||
ReferCode string `json:"refer_code,optional"`
|
||||
Identifier string `json:"identifier"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
Invite string `json:"invite,optional"`
|
||||
Code string `json:"code,optional"`
|
||||
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||
UserAgent string `header:"User-Agent,optional"`
|
||||
LoginType string `header:"Login-Type,optional"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
}
|
||||
|
||||
type UserSubscribeResp struct {
|
||||
|
||||
Reference in New Issue
Block a user