修复json的类型影响

This commit is contained in:
eson
2023-08-24 11:47:22 +08:00
parent 500611236e
commit d8ddad6fe9
18 changed files with 190 additions and 56 deletions

View File

@@ -74,6 +74,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
log.Println(jwtToken) // 通过websocket去, 送回通道
case "facebook":
case "fusen":
}

View File

@@ -60,7 +60,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
// 确认email 重新序列化
token.Email = req.Email
token.Wid = req.Wid
token.GuestId = req.GuestId
token.GuestId = userinfo.GuestId
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
if err != nil {

View File

@@ -19,7 +19,6 @@ import (
"github.com/474420502/requests"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"golang.org/x/net/proxy"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"gorm.io/gorm"
@@ -53,19 +52,6 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
if err != nil {
log.Fatal(err)
}
customClient := &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
},
}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, customClient)
var googleOauthConfig = &oauth2.Config{
RedirectURL: fmt.Sprintf("http://%s/api/user/oauth2/login/google", l.svcCtx.Config.MainAddress),
ClientID: l.svcCtx.Config.OAuth.Google.Appid,
@@ -74,15 +60,13 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
Endpoint: google.Endpoint,
}
token, err := googleOauthConfig.Exchange(ctx, req.Code)
token, err := googleOauthConfig.Exchange(l.ctx, req.Code)
if err != nil {
logx.Error(err)
resp.SetStatus(basic.CodeApiErr)
}
ses := requests.NewSession()
ses.Config().SetProxy("socks5://127.0.0.1:1080") // 代理 为了测试功能
r, err := ses.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
if err != nil {
logx.Error(err)

View File

@@ -0,0 +1,75 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"time"
"context"
"fusenapi/server/auth/internal/svc"
"fusenapi/server/auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UserRegisterLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
return &UserRegisterLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *UserRegisterLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
// 邮箱验证格式错误
if !auth.ValidateEmail(req.Email) {
return resp.SetStatus(basic.CodeOAuthEmailErr)
}
token := &auth.RegisterToken{
OperateType: auth.OpTypeRegister,
Id: 0,
GuestId: userinfo.GuestId,
Wid: req.Wid,
Email: req.Email,
Password: req.Password,
Platform: "fusen",
CreateAt: time.Now(),
}
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
}
// 进入发送邮箱的系统
EmailManager.EmailTasks <- &EmailFormat{
TargetEmail: req.Email,
CompanyName: "fusen",
ConfirmationLink: clurl,
SenderName: "support@fusenpack.com",
SenderTitle: "register-valid",
} // email进入队
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *UserRegisterLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -47,7 +47,7 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
token := &auth.ResetToken{
// 操作的类型, 验证的token 必须要继承这个
OperateType: auth.OpTypeResetToken,
UserId: uint64(userinfo.UserId),
UserId: userinfo.UserId,
Wid: req.Wid,
Email: *user.Email,
OldPassword: *user.PasswordHash,