debug toekn
This commit is contained in:
parent
c35e1402c3
commit
8d7ee20a28
|
@ -36,7 +36,7 @@ func (l *DebugAuthDeleteLogic) DebugAuthDelete(req *types.RequestAuthDelete, use
|
|||
|
||||
err := l.svcCtx.AllModels.FsUser.DebugAuthDelete(l.ctx, req.Email)
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -88,7 +88,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
user, err := l.svcCtx.AllModels.FsUser.RegisterByGoogleOAuth(l.ctx, token)
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
err = FinishRegister(l.svcCtx, user, token)
|
||||
|
@ -117,7 +117,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.Token) // ResetToken
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err)
|
||||
}
|
||||
|
||||
if time.Since(rt.CreateAt) > 30*time.Minute {
|
||||
|
@ -126,7 +126,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
|
||||
// TODO: 存储
|
||||
if rt.OperateType != auth.OpTypeResetToken {
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, "error OperateType: rt.OperateType != auth.OpTypeResetToken")
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, fmt.Errorf("error OperateType: rt.OperateType != auth.OpTypeResetToken"))
|
||||
}
|
||||
|
||||
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
|
||||
|
@ -142,14 +142,14 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId)
|
||||
err = wevent.CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event)
|
||||
if err != nil {
|
||||
logx.Error(err, rt.TraceId)
|
||||
return resp.SetStatus(basic.CodeResetPasswordErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeResetPasswordErr, err)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -64,13 +64,13 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
|
|||
token, err := googleOauthConfig.Exchange(l.ctx, req.Code)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeApiErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeApiErr, err)
|
||||
}
|
||||
|
||||
r, err := requests.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthGoogleApiErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthGoogleApiErr, err)
|
||||
}
|
||||
|
||||
gresult := r.Json()
|
||||
|
|
|
@ -46,12 +46,12 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
|
|||
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.ResetToken) // ResetToken
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err)
|
||||
}
|
||||
|
||||
// TODO: 存储
|
||||
if rt.OperateType != auth.OpTypeResetToken {
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, "error OperateType: rt.OperateType != auth.OpTypeResetToken")
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, fmt.Errorf("error OperateType: rt.OperateType != auth.OpTypeResetToken"))
|
||||
}
|
||||
|
||||
if time.Since(rt.CreateAt) > 30*time.Minute {
|
||||
|
|
|
@ -56,7 +56,7 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
|
|||
resetToken, err := l.svcCtx.ResetTokenManger.Encrypt(token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenEncryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenEncryptErr, err)
|
||||
}
|
||||
|
||||
userName := *user.FirstName + " " + *user.LastName
|
||||
|
|
|
@ -41,8 +41,8 @@ func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileRequest, us
|
|||
|
||||
err := l.svcCtx.AllModels.FsUserInfo.MergeMetadata(userinfo.UserId, req)
|
||||
if err != nil {
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) // 返回数据库创建错误
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err) // 返回数据库创建错误
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -131,40 +131,26 @@ func (resp *Response) Set(Code int, Message string) *Response {
|
|||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数, 第二个data就是debug参数
|
||||
func (resp *Response) SetStatus(sr *StatusResponse, dataAndDebug ...interface{}) *Response {
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
if err, ok := data[0].(error); ok {
|
||||
if err, ok := dataAndDebug[0].(error); ok {
|
||||
newResp.Message = err.Error()
|
||||
} else {
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
}
|
||||
case 2:
|
||||
var dataIndex = 0
|
||||
if err, ok := data[dataIndex].(error); ok {
|
||||
newResp.Message = err.Error()
|
||||
dataIndex++
|
||||
} else {
|
||||
panic("data只接收1或2个 data 或 error.Error() 和 data ")
|
||||
}
|
||||
newResp.Data = data[1]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收1或2个 data, error.Error() 和 data ")
|
||||
}
|
||||
|
@ -172,18 +158,32 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon
|
|||
return newResp
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数, 第二个data就是debug参数
|
||||
func (resp *Response) SetWithDebug(sr *StatusResponse, debug interface{}) *Response {
|
||||
|
||||
resp = &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message,
|
||||
Debug: debug,
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data ...interface{}) *Response {
|
||||
func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, dataAndDebug ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: msg,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
case 2:
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收一个 data")
|
||||
}
|
||||
|
@ -191,17 +191,20 @@ func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data
|
|||
return newResp
|
||||
}
|
||||
|
||||
func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data ...interface{}) *Response {
|
||||
func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, dataAndDebug ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message + ":" + msg,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
case 2:
|
||||
newResp.Data = dataAndDebug[0]
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收一个 data")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user