fix
This commit is contained in:
parent
1120dec011
commit
1bb5d4518a
|
@ -2,6 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/wevent"
|
||||
|
@ -34,6 +35,56 @@ func NewUserEmailConfirmationLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
|||
// func (l *UserEmailConfirmationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func FinishRegister(svcCtx *svc.ServiceContext, user *gmodel.FsUser, token *auth.RegisterToken) error {
|
||||
// 创建签证
|
||||
jwtToken, err := auth.GenerateJwtTokenUint64(
|
||||
auth.StringToHash(*user.PasswordHash),
|
||||
svcCtx.Config.Auth.AccessExpire,
|
||||
time.Now().UTC().Unix(),
|
||||
user.Id,
|
||||
0,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, token.TraceId)
|
||||
event.Data = wevent.DataEmailRegister{
|
||||
JwtToken: jwtToken,
|
||||
}
|
||||
err = CommonNotify(svcCtx.Config.MainAddress, token.Wid, event)
|
||||
if err != nil {
|
||||
// logx.Error(err, token.TraceId)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CommonNotify(MainAddress, wid string, event *wevent.WebsocketEvent) error {
|
||||
tp := requests.Post(fmt.Sprintf("%s/api/websocket/common_notify", MainAddress))
|
||||
tp.SetBodyJson(requests.M{
|
||||
"wid": wid,
|
||||
"data": event,
|
||||
})
|
||||
|
||||
wresp, err := tp.Execute()
|
||||
if err != nil {
|
||||
// logx.Error(err, token.TraceId)
|
||||
return err
|
||||
}
|
||||
|
||||
result := wresp.Json()
|
||||
if result.Get("code").Int() != 200 {
|
||||
// logx.Error(result.Get("message"))
|
||||
return fmt.Errorf("%s", result.Get("message").Str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEmailConfirmation, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
@ -59,43 +110,8 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
// 创建签证
|
||||
jwtToken, err := auth.GenerateJwtTokenUint64(
|
||||
auth.StringToHash(*user.PasswordHash),
|
||||
l.svcCtx.Config.Auth.AccessExpire,
|
||||
time.Now().Unix(),
|
||||
user.Id,
|
||||
0,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
return
|
||||
}
|
||||
|
||||
event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, token.TraceId)
|
||||
event.Data = wevent.DataEmailRegister{
|
||||
JwtToken: jwtToken,
|
||||
}
|
||||
|
||||
tp := requests.Post(fmt.Sprintf("%s/api/websocket/common_notify", l.svcCtx.Config.MainAddress))
|
||||
tp.SetBodyJson(requests.M{
|
||||
"wid": token.Wid,
|
||||
"data": event,
|
||||
})
|
||||
|
||||
wresp, err := tp.Execute()
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
return
|
||||
}
|
||||
|
||||
result := wresp.Json()
|
||||
if result.Get("code").Int() != 200 {
|
||||
logx.Error(result.Get("message"))
|
||||
return
|
||||
}
|
||||
logx.Info("success", token.TraceId, jwtToken)
|
||||
FinishRegister(l.svcCtx, user, token)
|
||||
logx.Info("success", token.TraceId)
|
||||
|
||||
case "facebook":
|
||||
case "fusen":
|
||||
|
@ -106,38 +122,8 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
// 创建签证
|
||||
jwtToken, err := auth.GenerateJwtTokenUint64(
|
||||
auth.StringToHash(*user.PasswordHash),
|
||||
l.svcCtx.Config.Auth.AccessExpire,
|
||||
time.Now().Unix(),
|
||||
user.Id,
|
||||
0,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
return
|
||||
}
|
||||
|
||||
event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, token.TraceId)
|
||||
event.Data = wevent.DataEmailRegister{
|
||||
JwtToken: jwtToken,
|
||||
}
|
||||
tp := requests.Post(fmt.Sprintf("%s/api/websocket/common_notify", l.svcCtx.Config.MainAddress))
|
||||
tp.SetBodyJson(requests.M{
|
||||
"wid": token.Wid,
|
||||
"data": event,
|
||||
})
|
||||
wresp, err := tp.Execute()
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
}
|
||||
result := wresp.Json()
|
||||
if result.Get("code").Int() != 200 {
|
||||
logx.Error(result.Get("message"))
|
||||
}
|
||||
logx.Info("success", token.TraceId, jwtToken)
|
||||
FinishRegister(l.svcCtx, user, token)
|
||||
logx.Info("success", token.TraceId)
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
@ -16,7 +16,6 @@ type DataUserLogin struct {
|
|||
|
||||
type RequestUserRegister struct {
|
||||
Wid string `json:"wid"` // websocket的id
|
||||
GuestId int64 `json:"guest_id"` // 游客id
|
||||
FirstName string `json:"first_name"` // 首名
|
||||
LastName string `json:"last_name"` // 名
|
||||
Resetaurant string `json:"resetaurant"` // 餐厅类型
|
||||
|
|
|
@ -12,25 +12,25 @@ import "basic.api"
|
|||
service auth {
|
||||
@handler UserLoginHandler
|
||||
post /api/auth/login(RequestUserLogin) returns (response);
|
||||
|
||||
|
||||
@handler UserRegisterHandler
|
||||
post /api/auth/register(RequestUserRegister) returns (response);
|
||||
|
||||
|
||||
@handler AcceptCookieHandler
|
||||
post /api/auth/accept-cookie(request) returns (response);
|
||||
|
||||
|
||||
@handler UserGoogleLoginHandler
|
||||
get /api/auth/oauth2/login/google(RequestGoogleLogin) returns (response);
|
||||
|
||||
|
||||
@handler UserEmailConfirmationHandler
|
||||
get /api/auth/email/confirmation(RequestEmailConfirmation) returns (response);
|
||||
|
||||
|
||||
@handler UserEmailRegisterHandler
|
||||
post /api/auth/oauth2/register(RequestEmailRegister) returns (response);
|
||||
|
||||
|
||||
@handler UserResetTokenHandler
|
||||
get /api/auth/reset/token(RequestUserResetToken) returns (response);
|
||||
|
||||
|
||||
@handler UserResetPasswordHandler
|
||||
post /api/auth/reset/password(RequestUserResetPassword) returns (response);
|
||||
}
|
||||
|
@ -52,8 +52,7 @@ type (
|
|||
type (
|
||||
// UserAddAddressHandler 用户登录请求结构
|
||||
RequestUserRegister {
|
||||
Wid string `json:"wid"` // websocket的id
|
||||
GuestId int64 `json:"guest_id"` // 游客id
|
||||
Wid string `json:"wid"` // websocket的id
|
||||
|
||||
FirstName string `json:"first_name"` // 首名
|
||||
LastName string `json:"last_name"` // 名
|
||||
|
|
Loading…
Reference in New Issue
Block a user