tijiao
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"fusenapi/server/auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserEmailConfirmationLogic struct {
|
||||
@@ -51,13 +50,14 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
|
||||
switch token.Platform {
|
||||
case "google":
|
||||
|
||||
user, err := l.OpGoogleRegister(token)
|
||||
// 谷歌平台的注册流程
|
||||
user, err := l.svcCtx.AllModels.FsUser.RegisterByGoogleOAuth(l.ctx, token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
// 创建签证
|
||||
jwtToken, err := auth.GenerateJwtTokenUint64(
|
||||
auth.StringToHash(*user.PasswordHash),
|
||||
l.svcCtx.Config.Auth.AccessExpire,
|
||||
@@ -66,8 +66,15 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
0,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(jwtToken)
|
||||
|
||||
case "facebook":
|
||||
l.OpGoogleRegister(token)
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -81,41 +88,3 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
// func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
|
||||
// OpGoogleRegister 谷歌平台的注册流程
|
||||
func (l *UserEmailConfirmationLogic) OpGoogleRegister(token *auth.RegisterToken) (*gmodel.FsUser, error) {
|
||||
user := &gmodel.FsUser{}
|
||||
|
||||
err := l.svcCtx.AllModels.FsUser.Transaction(context.TODO(), func(tx *gorm.DB) error {
|
||||
|
||||
err := tx.Model(user).Where("email = ?", token.Email).Take(user).Error
|
||||
if err != nil {
|
||||
// 没有找到在数据库就创建注册
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
createAt := time.Now().Unix()
|
||||
user.Email = &token.Email
|
||||
user.CreatedAt = &createAt
|
||||
user.GoogleId = &token.Id
|
||||
user.PasswordHash = &token.Password
|
||||
err = tx.Model(user).Create(user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 继承guest_id的资源表
|
||||
// tx.Table("fs_resources").Model()
|
||||
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
user.GoogleId = &token.Id
|
||||
return tx.Model(user).Update("google_id", user).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user