feat: 设备登录新增 base_payload 字段,前端传入后存储到 user_device 表
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 4m48s

This commit is contained in:
shanshanzhong 2026-04-20 20:08:20 -07:00
parent c0d839deb9
commit c8258dc93b
6 changed files with 44 additions and 27 deletions

View File

@ -154,6 +154,7 @@ type (
UserAgent string `json:"user_agent" validate:"required"` UserAgent string `json:"user_agent" validate:"required"`
CfToken string `json:"cf_token,optional"` CfToken string `json:"cf_token,optional"`
ShortCode string `json:"short_code,optional"` ShortCode string `json:"short_code,optional"`
BasePayload string `json:"base_payload,optional"`
} }
GenerateCaptchaResponse { GenerateCaptchaResponse {
Id string `json:"id"` Id string `json:"id"`

View File

@ -0,0 +1 @@
ALTER TABLE `user_device` DROP COLUMN `base_payload`;

View File

@ -0,0 +1 @@
ALTER TABLE `user_device` ADD COLUMN `base_payload` TEXT DEFAULT NULL COMMENT 'Base Payload' AFTER `short_code`;

View File

@ -96,6 +96,17 @@ func (l *DeviceLoginLogic) DeviceLogin(req *types.DeviceLoginRequest) (resp *typ
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query user failed: %v", err.Error()) return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query user failed: %v", err.Error())
} }
// Update base_payload if provided
if req.BasePayload != "" && req.BasePayload != deviceInfo.BasePayload {
deviceInfo.BasePayload = req.BasePayload
if updateErr := l.svcCtx.UserModel.UpdateDevice(l.ctx, deviceInfo); updateErr != nil {
l.Errorw("update device base_payload failed",
logger.Field("device_id", deviceInfo.Id),
logger.Field("error", updateErr.Error()),
)
}
}
// 注销后 device auth_method 被删除,重新登录时需要补回 // 注销后 device auth_method 被删除,重新登录时需要补回
hasDeviceAuth := false hasDeviceAuth := false
for _, am := range userInfo.AuthMethods { for _, am := range userInfo.AuthMethods {
@ -225,6 +236,7 @@ func (l *DeviceLoginLogic) registerUserAndDevice(req *types.DeviceLoginRequest)
UserAgent: req.UserAgent, UserAgent: req.UserAgent,
Identifier: req.Identifier, Identifier: req.Identifier,
ShortCode: req.ShortCode, ShortCode: req.ShortCode,
BasePayload: req.BasePayload,
Enabled: true, Enabled: true,
Online: false, Online: false,
} }

View File

@ -136,6 +136,7 @@ type Device struct {
UserAgent string `gorm:"default:null;comment:UserAgent."` UserAgent string `gorm:"default:null;comment:UserAgent."`
Identifier string `gorm:"type:varchar(255);unique;index:idx_identifier;default:'';comment:Device Identifier"` Identifier string `gorm:"type:varchar(255);unique;index:idx_identifier;default:'';comment:Device Identifier"`
ShortCode string `gorm:"type:varchar(255);default:'';comment:Short Code"` ShortCode string `gorm:"type:varchar(255);default:'';comment:Short Code"`
BasePayload string `gorm:"type:text;default:null;comment:Base Payload"`
Online bool `gorm:"default:false;not null;comment:Online"` Online bool `gorm:"default:false;not null;comment:Online"`
Enabled bool `gorm:"default:true;not null;comment:Enabled"` Enabled bool `gorm:"default:true;not null;comment:Enabled"`
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"` CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`

View File

@ -642,6 +642,7 @@ type DeviceLoginRequest struct {
UserAgent string `json:"user_agent" validate:"required"` UserAgent string `json:"user_agent" validate:"required"`
CfToken string `json:"cf_token,optional"` CfToken string `json:"cf_token,optional"`
ShortCode string `json:"short_code,optional"` ShortCode string `json:"short_code,optional"`
BasePayload string `json:"base_payload,optional"`
} }
type DissolveFamilyRequest struct { type DissolveFamilyRequest struct {