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.
|
err = txRes.
|
||||||
Where("guest_id = ?", guestId).
|
Where("guest_id = ?", guestId).
|
||||||
UpdateColumn("user_id", userId).Error
|
UpdateColumn("user_id", userId).Error
|
||||||
|
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -82,6 +81,15 @@ func InheritGuestIdResource(tx *gorm.DB, userId, guestId int64, afterDo func(txR
|
|||||||
}
|
}
|
||||||
|
|
||||||
if afterDo != nil {
|
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 afterDo(txRes, txUserMaterial, txUserInfo)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("guest_id must not be 0")
|
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 != nil {
|
||||||
// 没有找到在数据库就创建注册
|
// 没有找到在数据库就创建注册
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
|
||||||
createAt := time.Now().UTC().Unix()
|
createAt := time.Now().UTC().Unix()
|
||||||
user.Email = &token.Email
|
user.Email = &token.Email
|
||||||
user.CreatedAt = &createAt
|
user.CreatedAt = &createAt
|
||||||
@ -108,7 +115,6 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继承guest_id的资源表
|
// 继承guest_id的资源表
|
||||||
return InheritGuestIdResource(tx, user.Id, token.GuestId, nil)
|
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) {
|
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 {
|
err = u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
|
||||||
user = &FsUser{}
|
user = &FsUser{}
|
||||||
|
|
||||||
var err error
|
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 {
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
|
||||||
FirstName := token.Extend["first_name"].(string)
|
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)
|
Resetaurant := token.Extend["resetaurant"].(string)
|
||||||
|
|
||||||
createAt := time.Now().UTC().Unix()
|
createAt := time.Now().UTC().Unix()
|
||||||
|
|
||||||
user.Email = &token.Email
|
user.Email = &token.Email
|
||||||
user.CreatedAt = &createAt
|
user.CreatedAt = &createAt
|
||||||
user.PasswordHash = &token.Password
|
user.PasswordHash = &token.Password
|
||||||
user.FirstName = &FirstName
|
user.FirstName = &FirstName
|
||||||
user.LastName = &LastName
|
user.LastName = &LastName
|
||||||
|
|
||||||
err = UserTx.Create(user).Error
|
err = tx.Model(user).Create(user).Error
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logcontent += "create."
|
|
||||||
|
|
||||||
// 继承guest_id的资源表
|
// 继承guest_id的资源表
|
||||||
err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
|
err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
|
||||||
userProfile := &UserProfile{
|
userProfile := &UserProfile{
|
||||||
@ -191,13 +190,11 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||||||
Ctime: &now,
|
Ctime: &now,
|
||||||
Utime: &now,
|
Utime: &now,
|
||||||
}
|
}
|
||||||
logcontent += "profile."
|
|
||||||
|
|
||||||
err = txUserInfo.Create(uinfo).Error
|
err = txUserInfo.Create(uinfo).Error
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -210,7 +207,6 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||||||
return fmt.Errorf("the email had registered")
|
return fmt.Errorf("the email had registered")
|
||||||
})
|
})
|
||||||
|
|
||||||
logcontent += "end"
|
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/wevent"
|
"fusenapi/utils/wevent"
|
||||||
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -15,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/474420502/requests"
|
"github.com/474420502/requests"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,7 +113,10 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
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)
|
logx.Info("success", token.TraceId)
|
||||||
|
|
||||||
case "facebook":
|
case "facebook":
|
||||||
@ -120,11 +125,13 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||||||
user, err := l.svcCtx.AllModels.FsUser.RegisterByFusen(l.ctx, token)
|
user, err := l.svcCtx.AllModels.FsUser.RegisterByFusen(l.ctx, token)
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
logx.Error(err, ":", token.TraceId)
|
logx.Error(err, ":", token.TraceId)
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||||
}
|
}
|
||||||
|
err = FinishRegister(l.svcCtx, user, token)
|
||||||
FinishRegister(l.svcCtx, user, token)
|
if err != nil {
|
||||||
logx.Info("success", token.TraceId)
|
logx.Error(err)
|
||||||
|
}
|
||||||
|
logx.Info("success:", token.TraceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -135,6 +142,24 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
// func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
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…
x
Reference in New Issue
Block a user