Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
7bc05d393e
|
@ -60,7 +60,6 @@ func InheritGuestIdResource(tx *gorm.DB, userId, guestId int64, afterDo func(txR
|
|||
err = txRes.
|
||||
Where("guest_id = ?", guestId).
|
||||
UpdateColumn("user_id", userId).Error
|
||||
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
|
@ -82,6 +81,15 @@ func InheritGuestIdResource(tx *gorm.DB, userId, guestId int64, afterDo func(txR
|
|||
}
|
||||
|
||||
if afterDo != nil {
|
||||
if txRes.Error != nil {
|
||||
txRes = tx.Model(&FsResource{})
|
||||
}
|
||||
if txUserMaterial.Error != nil {
|
||||
txUserMaterial = tx.Model(&FsUserMaterial{})
|
||||
}
|
||||
if txUserInfo.Error != nil {
|
||||
txUserInfo = tx.Model(&FsUserInfo{})
|
||||
}
|
||||
return afterDo(txRes, txUserMaterial, txUserInfo)
|
||||
}
|
||||
return fmt.Errorf("guest_id must not be 0")
|
||||
|
@ -98,7 +106,6 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
|
|||
if err != nil {
|
||||
// 没有找到在数据库就创建注册
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
||||
createAt := time.Now().UTC().Unix()
|
||||
user.Email = &token.Email
|
||||
user.CreatedAt = &createAt
|
||||
|
@ -108,7 +115,6 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 继承guest_id的资源表
|
||||
return InheritGuestIdResource(tx, user.Id, token.GuestId, nil)
|
||||
}
|
||||
|
@ -137,19 +143,13 @@ type UserProfile struct {
|
|||
// 自平台的注册流程
|
||||
func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterToken) (user *FsUser, err error) {
|
||||
|
||||
logcontent := ""
|
||||
defer func() {
|
||||
logx.Info("aaaa:", logcontent, " ", err.Error())
|
||||
}()
|
||||
|
||||
err = u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
user = &FsUser{}
|
||||
|
||||
var err error
|
||||
UserTx := tx.Model(user)
|
||||
err = UserTx.Where("email = ?", token.Email).Take(user).Error
|
||||
|
||||
userTx := tx.Model(user)
|
||||
err = userTx.Where("email = ?", token.Email).Take(user).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
||||
FirstName := token.Extend["first_name"].(string)
|
||||
|
@ -157,20 +157,19 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
Resetaurant := token.Extend["resetaurant"].(string)
|
||||
|
||||
createAt := time.Now().UTC().Unix()
|
||||
|
||||
user.Email = &token.Email
|
||||
user.CreatedAt = &createAt
|
||||
user.PasswordHash = &token.Password
|
||||
user.FirstName = &FirstName
|
||||
user.LastName = &LastName
|
||||
|
||||
err = UserTx.Create(user).Error
|
||||
err = tx.Model(user).Create(user).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logx.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
logcontent += "create."
|
||||
|
||||
// 继承guest_id的资源表
|
||||
err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
|
||||
userProfile := &UserProfile{
|
||||
|
@ -191,13 +190,11 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
Ctime: &now,
|
||||
Utime: &now,
|
||||
}
|
||||
logcontent += "profile."
|
||||
|
||||
err = txUserInfo.Create(uinfo).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
|
@ -210,7 +207,6 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
return fmt.Errorf("the email had registered")
|
||||
})
|
||||
|
||||
logcontent += "end"
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/wevent"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
@ -15,6 +16,7 @@ import (
|
|||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -111,7 +113,10 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
FinishRegister(l.svcCtx, user, token)
|
||||
err = FinishRegister(l.svcCtx, user, token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
logx.Info("success", token.TraceId)
|
||||
|
||||
case "facebook":
|
||||
|
@ -120,11 +125,13 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
user, err := l.svcCtx.AllModels.FsUser.RegisterByFusen(l.ctx, token)
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logx.Error(err, ":", token.TraceId)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
}
|
||||
|
||||
FinishRegister(l.svcCtx, user, token)
|
||||
logx.Info("success", token.TraceId)
|
||||
err = FinishRegister(l.svcCtx, user, token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
logx.Info("success:", token.TraceId)
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -135,6 +142,24 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
successHtml := `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>注册成功</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>恭喜!您的注册成功。</h1>
|
||||
|
||||
<p>感谢您在我们网站进行注册。您的账号已经激活。</p>
|
||||
|
||||
<p>您现在可以使用您的邮箱地址和密码登录我们的网站,享受完整的服务和功能。</p>
|
||||
|
||||
<p>再次感谢您的信任和支持。如果您有任何问题,请随时联系我们。</p>
|
||||
|
||||
<p>祝您使用愉快!</p>
|
||||
</body>
|
||||
</html>`
|
||||
w.Write([]byte(successHtml))
|
||||
httpx.OkJsonCtx(r.Context(), w, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user