From a560098b3467ca9cdc1134932dbc44231e8091f7 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 29 Aug 2023 18:00:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E5=90=88=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/etc/resource.yaml | 4 +- service/repositories/image_handle.go | 77 ++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/server/resource/etc/resource.yaml b/server/resource/etc/resource.yaml index 6c11c903..1eede2ad 100644 --- a/server/resource/etc/resource.yaml +++ b/server/resource/etc/resource.yaml @@ -18,8 +18,8 @@ AWS: Secret: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm Token: BLMService: - Url: "http://18.119.109.254:8999" - # Url: "http://192.168.1.7:8999" + # Url: "http://18.119.109.254:8999" + Url: "http://192.168.1.9:8999" LogoCombine: #Url: "http://192.168.1.7:8999/LogoCombine" Url: "http://18.119.109.254:8999/LogoCombine" \ No newline at end of file diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 9344d3a3..c0f396ed 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -33,6 +33,9 @@ type ( } ImageHandle = interface { + // 获取logo最新信息 + LogoInfo(ctx context.Context, in *LogoInfoReq) (*LogoInfoRes, error) + // logo信息 LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) @@ -44,6 +47,50 @@ type ( } ) +/* 获取logo最新信息 */ +type ( + LogoInfoReq struct { + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + } + LogoInfoRes struct { + Metadata *string `json:"metadata"` + LogoUrl *string `json:"logo_url"` + } +) + +func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*LogoInfoRes, error) { + var metadata *string + var logoUrl *string + + userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) + userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) + + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0) + if err != nil { + logx.Error(err) + return nil, err + } + metadata = userMaterialInfoDefault.Metadata + logoUrl = userMaterialInfoDefault.ResourceUrl + } else { + logx.Error(err) + return nil, err + } + } else { + metadata = userMaterialInfo.Metadata + logoUrl = userMaterialInfo.ResourceUrl + } + return &LogoInfoRes{ + Metadata: metadata, + LogoUrl: logoUrl, + }, nil +} + +/* 获取logo最新信息 */ + /* logo信息 */ type ( LogoInfoSetReq struct { @@ -106,34 +153,20 @@ type ( func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { // 查询logo最新基础信息 - var metadata *string - var logoUrl *string - userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) - userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) - + resLogoInfo, err := l.LogoInfo(ctx, &LogoInfoReq{ + UserId: in.UserId, + GuestId: in.GuestId, + }) if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0) - if err != nil { - logx.Error(err) - return nil, err - } - metadata = userMaterialInfoDefault.Metadata - logoUrl = userMaterialInfoDefault.ResourceUrl - } else { - logx.Error(err) - return nil, err - } - } else { - metadata = userMaterialInfo.Metadata - logoUrl = userMaterialInfo.ResourceUrl + logx.Error(err) + return nil, err } // 根据hash 查询数据资源 var hashKeyData = *in hashKeyData.GuestId = 0 hashKeyData.UserId = 0 - hashKeyData.LogoUrl = *logoUrl + hashKeyData.LogoUrl = *resLogoInfo.LogoUrl var hashKeyDataMap map[string]interface{} hashKeyDataB, _ := json.Marshal(hashKeyData) json.Unmarshal(hashKeyDataB, &hashKeyDataMap) @@ -184,7 +217,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq moduleDataMap["materialList"] = materialList var combineParam map[string]interface{} - json.Unmarshal([]byte(*metadata), &combineParam) + json.Unmarshal([]byte(*resLogoInfo.Metadata), &combineParam) combineParam["template_tagid"] = in.TemplateTag combineParam["website"] = in.Website combineParam["slogan"] = in.Slogan From 15692d60758b0baaf86f5a93c2f0f16eaeadf45b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 29 Aug 2023 18:06:39 +0800 Subject: [PATCH 2/3] fix --- model/gmodel/fs_user_logic.go | 47 +++++++++++++++++- .../handler/debugauthdeletehandler.go | 35 ++++++++++++++ server/auth/internal/handler/routes.go | 5 ++ .../internal/logic/debugauthdeletelogic.go | 48 +++++++++++++++++++ .../logic/useremailconfirmationlogic.go | 6 +-- .../internal/logic/usergoogleloginlogic.go | 2 +- .../auth/internal/logic/userregisterlogic.go | 2 +- server/auth/internal/types/types.go | 4 ++ server_api/auth.api | 8 ++++ utils/auth/register.go | 8 ++++ 10 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 server/auth/internal/handler/debugauthdeletehandler.go create mode 100644 server/auth/internal/logic/debugauthdeletelogic.go diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 257a683d..2248ce88 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -148,8 +148,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT user = &FsUser{} var err error - userTx := tx.Model(user) - err = userTx.Where("email = ?", token.Email).Take(user).Error + err = tx.Model(user).Where("email = ?", token.Email).Take(user).Error if err == gorm.ErrRecordNotFound { FirstName := token.Extend["first_name"].(string) @@ -234,3 +233,47 @@ func (u *FsUserModel) UpdateUserBasicInfoById(ctx context.Context, Id int64, use }).Error return err } + +func (u *FsUserModel) DebugAuthDelete(ctx context.Context, email string) (err error) { + + err = u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + user := &FsUser{} + + txUser := tx.Model(user) + err = txUser.Where("email = ?", email).Take(user).Error + if err == nil { + err = txUser.Where("email = ?", email).Delete(user).Error + if err != nil { + return err + } + txRes := tx.Model(&FsResource{}) + txUserMaterial := tx.Model(&FsUserMaterial{}) + txUserInfo := tx.Model(&FsUserInfo{}) + + // 继承guest_id的资源表 + err = txRes. + Where("user_id = ?", user.Id).Delete(&FsResource{}).Error + if err != nil && err != gorm.ErrRecordNotFound { + return err + } + + err = txUserMaterial. + Where("user_id = ?", user.Id). + Delete(&FsUserMaterial{}).Error + if err != nil && err != gorm.ErrRecordNotFound { + return err + } + + err = txUserInfo. + Where("user_id = ?", user.Id). + Delete(&FsResource{}).Error + if err != nil && err != gorm.ErrRecordNotFound { + return err + } + } + + return nil + }) + + return err +} diff --git a/server/auth/internal/handler/debugauthdeletehandler.go b/server/auth/internal/handler/debugauthdeletehandler.go new file mode 100644 index 00000000..71bb5365 --- /dev/null +++ b/server/auth/internal/handler/debugauthdeletehandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/auth/internal/logic" + "fusenapi/server/auth/internal/svc" + "fusenapi/server/auth/internal/types" +) + +func DebugAuthDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.RequestAuthDelete + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewDebugAuthDeleteLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.DebugAuthDelete(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/auth/internal/handler/routes.go b/server/auth/internal/handler/routes.go index 2ed3bfad..121d86c8 100644 --- a/server/auth/internal/handler/routes.go +++ b/server/auth/internal/handler/routes.go @@ -52,6 +52,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/auth/reset/password", Handler: UserResetPasswordHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/debug/auth/delete", + Handler: DebugAuthDeleteHandler(serverCtx), + }, }, ) } diff --git a/server/auth/internal/logic/debugauthdeletelogic.go b/server/auth/internal/logic/debugauthdeletelogic.go new file mode 100644 index 00000000..a841c396 --- /dev/null +++ b/server/auth/internal/logic/debugauthdeletelogic.go @@ -0,0 +1,48 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/auth/internal/svc" + "fusenapi/server/auth/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DebugAuthDeleteLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDebugAuthDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DebugAuthDeleteLogic { + return &DebugAuthDeleteLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *DebugAuthDeleteLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *DebugAuthDeleteLogic) DebugAuthDelete(req *types.RequestAuthDelete, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + err := l.svcCtx.AllModels.FsUser.DebugAuthDelete(l.ctx, req.Email) + if err != nil { + return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) + } + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *DebugAuthDeleteLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index a9cda652..85b6de3b 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -105,7 +105,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma } logx.Info(token.Platform) switch token.Platform { - case "google": + case string(auth.PLATFORM_GOOGLE): // 谷歌平台的注册流程 user, err := l.svcCtx.AllModels.FsUser.RegisterByGoogleOAuth(l.ctx, token) if err != nil { @@ -119,8 +119,8 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma } logx.Info("success", token.TraceId) - case "facebook": - case "fusen": + case string(auth.PLATFORM_FACEBOOK): + case string(auth.PLATFORM_FUSEN): // log.Println("aaaa", token) user, err := l.svcCtx.AllModels.FsUser.RegisterByFusen(l.ctx, token) if err != nil && err != gorm.ErrRecordNotFound { diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index 2a4372ec..96879180 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -93,7 +93,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us l.registerInfo = &auth.RegisterToken{ Password: base64.RawURLEncoding.EncodeToString(nonce), - Platform: "google", + Platform: string(auth.PLATFORM_GOOGLE), OperateType: auth.OpTypeRegister, TraceId: uuid.NewString(), CreateAt: time.Now().UTC(), diff --git a/server/auth/internal/logic/userregisterlogic.go b/server/auth/internal/logic/userregisterlogic.go index 3840dffe..513c2ac2 100644 --- a/server/auth/internal/logic/userregisterlogic.go +++ b/server/auth/internal/logic/userregisterlogic.go @@ -47,7 +47,7 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf Wid: req.Wid, Email: req.Email, Password: req.Password, - Platform: "fusen", + Platform: string(auth.PLATFORM_FUSEN), TraceId: uuid.NewString(), CreateAt: time.Now(), Extend: map[string]interface{}{ diff --git a/server/auth/internal/types/types.go b/server/auth/internal/types/types.go index f052b217..e7f6d228 100644 --- a/server/auth/internal/types/types.go +++ b/server/auth/internal/types/types.go @@ -5,6 +5,10 @@ import ( "fusenapi/utils/basic" ) +type RequestAuthDelete struct { + Email string `json:"email"` +} + type RequestUserLogin struct { Email string `json:"email"` Password string `json:"password"` diff --git a/server_api/auth.api b/server_api/auth.api index 4f5384dd..eeddb5e5 100644 --- a/server_api/auth.api +++ b/server_api/auth.api @@ -33,10 +33,18 @@ service auth { @handler UserResetPasswordHandler post /api/auth/reset/password(RequestUserResetPassword) returns (response); + + @handler DebugAuthDeleteHandler + post /api/debug/auth/delete(RequestAuthDelete) returns (response); } type ( + // RequestAuthDelete 用于debug + RequestAuthDelete { + Email string `json:"email"` + } + // UserAddAddressHandler 用户登录请求结构 RequestUserLogin { Email string `json:"email"` diff --git a/utils/auth/register.go b/utils/auth/register.go index 45d64019..3aacc85d 100644 --- a/utils/auth/register.go +++ b/utils/auth/register.go @@ -17,6 +17,14 @@ func init() { gob.Register(map[string]interface{}{}) } +type RegisterPlatform string + +const ( + PLATFORM_GOOGLE = "google" + PLATFORM_FUSEN = "fusen" + PLATFORM_FACEBOOK = "facebook" +) + type RegisterToken struct { OperateType // 操作的类型, 验证的token 必须要继承这个 GuestId int64 // guest_id 需要继承 From fc96d181b3ef77e0930582fdb4d98c8f9824718a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 29 Aug 2023 18:13:49 +0800 Subject: [PATCH 3/3] fix --- server/auth/internal/handler/routes.go | 2 +- server_api/auth.api | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/auth/internal/handler/routes.go b/server/auth/internal/handler/routes.go index 121d86c8..f8f1c8c4 100644 --- a/server/auth/internal/handler/routes.go +++ b/server/auth/internal/handler/routes.go @@ -54,7 +54,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodPost, - Path: "/api/debug/auth/delete", + Path: "/api/auth/debug/delete", Handler: DebugAuthDeleteHandler(serverCtx), }, }, diff --git a/server_api/auth.api b/server_api/auth.api index eeddb5e5..089aab6d 100644 --- a/server_api/auth.api +++ b/server_api/auth.api @@ -35,7 +35,7 @@ service auth { post /api/auth/reset/password(RequestUserResetPassword) returns (response); @handler DebugAuthDeleteHandler - post /api/debug/auth/delete(RequestAuthDelete) returns (response); + post /api/auth/debug/delete(RequestAuthDelete) returns (response); } type (