This commit is contained in:
eson
2023-08-29 14:19:47 +08:00
parent 79b6277332
commit 3103d69bae
8 changed files with 136 additions and 39 deletions

View File

@@ -90,7 +90,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
token, err := l.svcCtx.RegisterTokenManger.Decrypt(req.Token)
token, err := l.svcCtx.OAuthTokenManger.Decrypt(req.Token)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)

View File

@@ -47,7 +47,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
return resp.SetStatus(basic.CodeOAuthEmailErr)
}
token, err := l.svcCtx.RegisterTokenManger.Decrypt(req.RegisterToken)
token, err := l.svcCtx.OAuthTokenManger.Decrypt(req.RegisterToken)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
@@ -62,7 +62,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
token.Wid = req.Wid
token.GuestId = userinfo.GuestId
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
clurl, err := l.svcCtx.OAuthTokenManger.Generate(token)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)

View File

@@ -91,16 +91,19 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
}
l.registerInfo = &auth.RegisterToken{
Id: googleId,
Password: base64.RawURLEncoding.EncodeToString(nonce),
Platform: "google",
OperateType: auth.OpTypeRegister,
TraceId: uuid.NewString(),
CreateAt: time.Now(),
Extend: map[string]interface{}{
"google_id": googleId,
},
}
l.isRegistered = false
token, err := l.svcCtx.RegisterTokenManger.Encrypt(l.registerInfo)
token, err := l.svcCtx.OAuthTokenManger.Encrypt(l.registerInfo)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)

View File

@@ -43,7 +43,6 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
token := &auth.RegisterToken{
OperateType: auth.OpTypeRegister,
Id: 0,
GuestId: userinfo.GuestId,
Wid: req.Wid,
Email: req.Email,
@@ -51,9 +50,14 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
Platform: "fusen",
TraceId: uuid.NewString(),
CreateAt: time.Now(),
Extend: map[string]interface{}{
"first_name": req.FirstName,
"last_name": req.LastName,
"resetaurant": req.Resetaurant,
},
}
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
clurl, err := l.svcCtx.OAuthTokenManger.Generate(token)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)

View File

@@ -22,8 +22,8 @@ type ServiceContext struct {
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
RegisterTokenManger *auth.ConfirmationLink[auth.RegisterToken]
ResetTokenManger *auth.ConfirmationLink[auth.ResetToken]
OAuthTokenManger *auth.ConfirmationLink[auth.RegisterToken]
ResetTokenManger *auth.ConfirmationLink[auth.ResetToken]
}
func NewServiceContext(c config.Config) *ServiceContext {
@@ -31,12 +31,12 @@ func NewServiceContext(c config.Config) *ServiceContext {
// StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
registerAddress := fmt.Sprintf("%s/api/auth/email/confirmation", c.MainAddress)
return &ServiceContext{
Config: c,
MysqlConn: conn,
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
RegisterTokenManger: auth.NewConfirmationLink[auth.RegisterToken](c.Auth.AccessSecret, registerAddress),
ResetTokenManger: auth.NewConfirmationLink[auth.ResetToken](c.Auth.AccessSecret, registerAddress),
Config: c,
MysqlConn: conn,
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
OAuthTokenManger: auth.NewConfirmationLink[auth.RegisterToken](c.Auth.AccessSecret, registerAddress),
ResetTokenManger: auth.NewConfirmationLink[auth.ResetToken](c.Auth.AccessSecret, registerAddress),
}
}