修复序列化代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
@@ -31,8 +32,15 @@ func (l *AcceptCookieLogic) AcceptCookie(req *types.Request, userinfo *auth.User
|
||||
// userinfo 传入值时, 一定不为null
|
||||
idtyp := userinfo.GetIdType()
|
||||
if idtyp == auth.IDTYPE_Guest {
|
||||
return resp.SetStatus(basic.CodeDupGuestErr)
|
||||
return resp.SetStatus(basic.CodeGuestDupErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
m := gmodel.NewFsGuestModel(l.svcCtx.MysqlConn)
|
||||
token, err := m.GenerateGuestID(l.ctx, &l.svcCtx.Config.Auth.AccessSecret)
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeGuestGenErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, types.DataGuest{
|
||||
Token: token,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
@@ -28,7 +28,7 @@ func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
||||
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := model.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
userinfo.GetIdType()
|
||||
// user := auth.GetUserInfoFormCtx(l.ctx)
|
||||
// if user.UserId == 0 {
|
||||
@@ -36,7 +36,7 @@ func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *aut
|
||||
// }
|
||||
// user.UserId = 22
|
||||
// model里设置了 返回值. 和 types 里的一至可以直接返回
|
||||
data, err := m.FindDataAddressList(l.ctx, 22)
|
||||
data, err := m.GetUserAllAddress(l.ctx, 22)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
|
||||
@@ -2,7 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
@@ -26,14 +26,37 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
|
||||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
// 返回未授权
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
|
||||
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.Set(510, err.Error())
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
|
||||
// $userInfo->type = $userInfo->type != 0 ? $userInfo->type : '';
|
||||
// $userInfo->is_order_status_email = (boolean)$userInfo->is_order_status_email;
|
||||
// $userInfo->is_email_advertisement = (boolean)$userInfo->is_email_advertisement;
|
||||
// $userInfo->is_order_status_phone = (boolean)$userInfo->is_order_status_phone;
|
||||
// $userInfo->is_phone_advertisement = (boolean)$userInfo->is_phone_advertisement;
|
||||
// $userInfo->is_open_render = (boolean)$userInfo->is_open_render;
|
||||
// $userInfo->is_low_rendering = (boolean)$userInfo->is_low_rendering;
|
||||
// $userInfo->is_remove_bg = (boolean)$userInfo->is_remove_bg;
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
|
||||
Type: *user.Type,
|
||||
IsOrderStatusEmail: *user.IsOrderStatusEmail > 0,
|
||||
IsEmailAdvertisement: *user.IsEmailAdvertisement > 0,
|
||||
IsOrderStatusPhone: *user.IsOrderStatusPhone > 0,
|
||||
IsPhoneAdvertisement: *user.IsPhoneAdvertisement > 0,
|
||||
IsOpenRender: *user.IsOpenRender > 0,
|
||||
IsLowRendering: *user.IsLowRendering > 0,
|
||||
IsRemoveBg: *user.IsRemoveBg > 0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserFontsLogic struct {
|
||||
@@ -27,11 +28,10 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
|
||||
}
|
||||
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != nil {
|
||||
data, err := gmodel.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != gorm.ErrRecordNotFound && err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOK, data)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
@@ -28,8 +28,12 @@ func NewUserGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserG
|
||||
|
||||
func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserLoginLogic struct {
|
||||
@@ -29,26 +30,23 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
||||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Response, jwtToken string) {
|
||||
// 创建一个 FsUserModel 对象 m 并实例化之,该对象用于操作 MySQL 数据库中的用户数据表。
|
||||
m := model.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
|
||||
// 在用户数据表中根据登录名查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
||||
userModel, err := m.FindOneByEmail(l.ctx, req.Name)
|
||||
|
||||
// 如果在用户数据表中没有找到登录名匹配的用户记录,则抛出 ErrNotFound 错误并返回未认证的状态码以及错误信息。
|
||||
if err == model.ErrNotFound {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()), jwtToken
|
||||
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
||||
user, err := m.FindUserByEmail(l.ctx, req.Name)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
|
||||
}
|
||||
|
||||
// 如果在用户数据表中找到了登录名匹配的用户记录,则判断密码是否匹配。
|
||||
if userModel.PasswordHash != req.Password {
|
||||
if *user.PasswordHash != req.Password {
|
||||
logx.Info("密码错误")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "密码错误"), jwtToken
|
||||
return resp.SetStatus(basic.CodePasswordErr), jwtToken
|
||||
}
|
||||
|
||||
// 如果密码匹配,则生成 JWT Token。
|
||||
nowSec := time.Now().Unix()
|
||||
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, int64(userModel.Id), 0)
|
||||
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
|
||||
|
||||
// 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
|
||||
if err != nil {
|
||||
@@ -56,9 +54,6 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Res
|
||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
||||
}
|
||||
|
||||
// 更新 MySQL 数据库中用户记录对应的 VerificationToken 字段值为生成的 JWT Token。
|
||||
err = m.UpdateVerificationToken(l.ctx, userModel.Id, jwtToken)
|
||||
|
||||
// 如果更新 VerificationToken 字段失败,则返回未认证的状态码。
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
||||
|
||||
@@ -2,9 +2,9 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/basic"
|
||||
@@ -27,19 +27,16 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
|
||||
return resp
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err == gmodel.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user