feat(user): 添加QQ绑定功能并重构用户登录逻辑

- 在BaseSysUser模型中添加QQ字段,移除密码字段(暂时注释)
- 移除base.bbs.go中的GetUserInfo函数,将其迁移至base_sys_user.go
- 将登录服务中的外部API调用逻辑整合到BaseSysUserService
- 新增BindQQ方法实现QQ号绑定功能,包含重复绑定检查
- 更新GetUserInfo方法,完善用户信息获取和同步逻辑
- 优化导入包,移除未使用的依赖项
```
This commit is contained in:
昔念
2026-03-24 11:56:36 +08:00
parent 705eb31007
commit 5320dffdd8
4 changed files with 148 additions and 146 deletions

View File

@@ -2,8 +2,6 @@ package service
import (
"context"
"fmt"
"log"
"strings"
"time"
@@ -15,7 +13,6 @@ import (
"blazing/modules/base/config"
"blazing/modules/base/model"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/encoding/gbase64"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@@ -38,11 +35,10 @@ type TokenResult struct {
// Login 登录
func (s *BaseSysLoginService) Login(ctx context.Context, req *v1.BaseOpenLoginReq) (result *TokenResult, err error) {
var (
captchaId = req.CaptchaId
verifyCode = req.VerifyCode
password = req.Password
username = req.Username
baseSysUser = model.NewBaseSysUser()
captchaId = req.CaptchaId
verifyCode = req.VerifyCode
password = req.Password
username = req.Username
)
username = strings.ToLower(username)
vcode, _ := cool.CacheManager.Get(ctx, "login:"+captchaId)
@@ -51,62 +47,11 @@ func (s *BaseSysLoginService) Login(ctx context.Context, req *v1.BaseOpenLoginRe
return
}
// 调用方法
userInfo, err := GetUserInfo(username, password)
user, err := NewBaseSysUserService().GetUserInfo(username, password)
if err != nil {
err = gerror.New("用户系统错误")
return
}
// // 输出结果
// fmt.Printf("用户名: %s\n", userInfo.Data.Attributes.Username)
// fmt.Printf("显示名: %s\n", userInfo.Data.Attributes.DisplayName)
// fmt.Printf("头像: %s\n", userInfo.Data.Attributes.AvatarUrl)
// fmt.Printf("加入时间: %s\n", userInfo.Data.Attributes.JoinTime)
// fmt.Printf("金钱: %.2f\n", userInfo.Data.Attributes.Money)
// fmt.Printf("用户组: %s\n", userInfo.Included[0].Attributes.NameSingular)
md5password, _ := gmd5.Encrypt(password)
var user *model.BaseSysUser
if !strings.EqualFold(userInfo.Data.Attributes.Username, username) { //说明没查找到用户
//后端添加的账户
cool.DBM(baseSysUser).Where("username=?", username).Where("password=?", md5password).Where("status=?", 1).Scan(&user)
if user == nil {
err = gerror.New("账户或密码不正确~")
return
}
} else {
m := cool.DBM(baseSysUser).Where("username=?", username)
m.Scan(&user)
if user == nil {
//这里实现注册用户
//err = gerror.New("账户或密码不正确~")
// return
NewBaseSysUserService().Gen(userInfo.Data.Attributes)
m := cool.DBM(baseSysUser).Where("username=?", username)
m.Scan(&user)
} else {
if *user.Status == 0 {
err = gerror.New("账户被封禁~")
return
}
user.HeadImg = &userInfo.Data.Attributes.AvatarUrl
var ttt = *user.PasswordV + 1
user.PasswordV = &ttt
_, err := m.Save(user)
if err != nil {
log.Fatal(err)
}
cool.CacheManager.Set(ctx, fmt.Sprintf("admin:passwordVersion:%d", user.ID), ttt, 0)
}
}
result, err = s.generateTokenByUser(ctx, user)
if err != nil {
return
@@ -134,7 +79,7 @@ func (*BaseSysLoginService) Captcha(req *v1.BaseOpenCaptchaReq) (interface{}, er
result.Data = `data:image/svg+xml;base64,` + svgbase64
result.CaptchaId = guid.S()
cool.CacheManager.Set(ctx, "login:"+result.CaptchaId, captchaText, 1800*time.Second)
return result, err
}