refactor(auth): 优化设备登录逻辑,移除冗余代码并添加设备缓存
Build docker and publish / build (20.15.1) (push) Failing after 6m39s

feat(database): 添加用户算法和盐字段的迁移脚本

fix(subscribe): 修复服务器用户列表缓存问题,临时禁用缓存

style(model): 清理用户模型注释,简化代码结构

chore: 删除无用脚本和测试文件

docs: 添加用户绑定流程文档

perf(login): 优化设备登录性能,添加设备缓存键

fix(unbind): 修复设备解绑时的缓存清理逻辑

refactor(verify): 简化邮箱验证逻辑,移除冗余代码

build(docker): 更新Dockerfile配置,使用scratch基础镜像
This commit is contained in:
2025-10-28 20:46:21 -07:00
parent e6bd78aa76
commit 0f38b3fcd3
33 changed files with 226 additions and 1605 deletions
+1 -4
View File
@@ -20,10 +20,7 @@ func (m *defaultUserModel) FindUserAuthMethodByOpenID(ctx context.Context, metho
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error {
return conn.Model(&AuthMethods{}).Where("auth_type = ? AND auth_identifier = ?", method, openID).First(&data).Error
})
if err != nil {
return nil, err
}
return &data, nil
return &data, err
}
func (m *defaultUserModel) FindUserAuthMethodByPlatform(ctx context.Context, userId int64, platform string) (*AuthMethods, error) {
+22 -23
View File
@@ -4,30 +4,29 @@ import (
"time"
)
// User 用户模型结构体
type User struct {
Id int64 `gorm:"primaryKey"` // 用户主键ID
Password string `gorm:"type:varchar(100);not null;comment:User Password"` // 用户密码(加密存储)
Algo string `gorm:"type:varchar(20);default:'default';comment:Encryption Algorithm"` // 密码加密算法
Salt string `gorm:"type:varchar(20);default:null;comment:Password Salt"` // 密码盐值
Avatar string `gorm:"type:MEDIUMTEXT;comment:User Avatar"` // 用户头像
Balance int64 `gorm:"default:0;comment:User Balance"` // 用户余额(以分为单位)
ReferCode string `gorm:"type:varchar(20);default:'';comment:Referral Code"` // 用户推荐码
RefererId int64 `gorm:"index:idx_referer;comment:Referrer ID"` // 推荐人ID
Commission int64 `gorm:"default:0;comment:Commission"` // 佣金金额
ReferralPercentage uint8 `gorm:"default:0;comment:Referral"` // 推荐奖励百分比
OnlyFirstPurchase *bool `gorm:"default:true;not null;comment:Only First Purchase"` // 是否仅首次购买给推荐奖励
GiftAmount int64 `gorm:"default:0;comment:User Gift Amount"` // 用户赠送金额
Enable *bool `gorm:"default:true;not null;comment:Is Account Enabled"` // 账户是否启用
IsAdmin *bool `gorm:"default:false;not null;comment:Is Admin"` // 是否为管理员
EnableBalanceNotify *bool `gorm:"default:false;not null;comment:Enable Balance Change Notifications"` // 是否启用余额变动通知
EnableLoginNotify *bool `gorm:"default:false;not null;comment:Enable Login Notifications"` // 是否启用登录通知
EnableSubscribeNotify *bool `gorm:"default:false;not null;comment:Enable Subscription Notifications"` // 是否启用订阅通知
EnableTradeNotify *bool `gorm:"default:false;not null;comment:Enable Trade Notifications"` // 是否启用交易通知
AuthMethods []AuthMethods `gorm:"foreignKey:UserId;references:Id"` // 用户认证方式列表
UserDevices []Device `gorm:"foreignKey:UserId;references:Id"` // 用户设备列表
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"` // 创建时间
UpdatedAt time.Time `gorm:"comment:Update Time"` // 更新时间
Id int64 `gorm:"primaryKey"`
Password string `gorm:"type:varchar(100);not null;comment:User Password"`
Algo string `gorm:"type:varchar(20);default:'default';comment:Encryption Algorithm"`
Salt string `gorm:"type:varchar(20);default:null;comment:Password Salt"`
Avatar string `gorm:"type:MEDIUMTEXT;comment:User Avatar"`
Balance int64 `gorm:"default:0;comment:User Balance"` // User Balance Amount
ReferCode string `gorm:"type:varchar(20);default:'';comment:Referral Code"`
RefererId int64 `gorm:"index:idx_referer;comment:Referrer ID"`
Commission int64 `gorm:"default:0;comment:Commission"` // Commission Amount
ReferralPercentage uint8 `gorm:"default:0;comment:Referral"` // Referral Percentage
OnlyFirstPurchase *bool `gorm:"default:true;not null;comment:Only First Purchase"` // Only First Purchase Referral
GiftAmount int64 `gorm:"default:0;comment:User Gift Amount"`
Enable *bool `gorm:"default:true;not null;comment:Is Account Enabled"`
IsAdmin *bool `gorm:"default:false;not null;comment:Is Admin"`
EnableBalanceNotify *bool `gorm:"default:false;not null;comment:Enable Balance Change Notifications"`
EnableLoginNotify *bool `gorm:"default:false;not null;comment:Enable Login Notifications"`
EnableSubscribeNotify *bool `gorm:"default:false;not null;comment:Enable Subscription Notifications"`
EnableTradeNotify *bool `gorm:"default:false;not null;comment:Enable Trade Notifications"`
AuthMethods []AuthMethods `gorm:"foreignKey:UserId;references:Id"`
UserDevices []Device `gorm:"foreignKey:UserId;references:Id"`
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
UpdatedAt time.Time `gorm:"comment:Update Time"`
}
func (*User) TableName() string {