feat: 设备登录新增 base_payload 字段,前端传入后存储到 user_device 表
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 4m48s
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 4m48s
This commit is contained in:
parent
c0d839deb9
commit
c8258dc93b
@ -149,11 +149,12 @@ type (
|
||||
State string `form:"state"`
|
||||
}
|
||||
DeviceLoginRequest {
|
||||
Identifier string `json:"identifier" validate:"required"`
|
||||
IP string `header:"X-Original-Forwarded-For"`
|
||||
UserAgent string `json:"user_agent" validate:"required"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
ShortCode string `json:"short_code,optional"`
|
||||
Identifier string `json:"identifier" validate:"required"`
|
||||
IP string `header:"X-Original-Forwarded-For"`
|
||||
UserAgent string `json:"user_agent" validate:"required"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
ShortCode string `json:"short_code,optional"`
|
||||
BasePayload string `json:"base_payload,optional"`
|
||||
}
|
||||
GenerateCaptchaResponse {
|
||||
Id string `json:"id"`
|
||||
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE `user_device` DROP COLUMN `base_payload`;
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE `user_device` ADD COLUMN `base_payload` TEXT DEFAULT NULL COMMENT 'Base Payload' AFTER `short_code`;
|
||||
@ -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())
|
||||
}
|
||||
|
||||
// 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 被删除,重新登录时需要补回
|
||||
hasDeviceAuth := false
|
||||
for _, am := range userInfo.AuthMethods {
|
||||
@ -220,13 +231,14 @@ func (l *DeviceLoginLogic) registerUserAndDevice(req *types.DeviceLoginRequest)
|
||||
|
||||
// Insert device record
|
||||
deviceInfo := &user.Device{
|
||||
Ip: req.IP,
|
||||
UserId: userInfo.Id,
|
||||
UserAgent: req.UserAgent,
|
||||
Identifier: req.Identifier,
|
||||
ShortCode: req.ShortCode,
|
||||
Enabled: true,
|
||||
Online: false,
|
||||
Ip: req.IP,
|
||||
UserId: userInfo.Id,
|
||||
UserAgent: req.UserAgent,
|
||||
Identifier: req.Identifier,
|
||||
ShortCode: req.ShortCode,
|
||||
BasePayload: req.BasePayload,
|
||||
Enabled: true,
|
||||
Online: false,
|
||||
}
|
||||
if err := db.Create(deviceInfo).Error; err != nil {
|
||||
l.Errorw("failed to insert device",
|
||||
|
||||
@ -130,16 +130,17 @@ func (*AuthMethods) TableName() string {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
Ip string `gorm:"type:varchar(255);not null;comment:Device IP"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
UserAgent string `gorm:"default:null;comment:UserAgent."`
|
||||
Identifier string `gorm:"type:varchar(255);unique;index:idx_identifier;default:'';comment:Device Identifier"`
|
||||
ShortCode string `gorm:"type:varchar(255);default:'';comment:Short Code"`
|
||||
Online bool `gorm:"default:false;not null;comment:Online"`
|
||||
Enabled bool `gorm:"default:true;not null;comment:Enabled"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
Ip string `gorm:"type:varchar(255);not null;comment:Device IP"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
UserAgent string `gorm:"default:null;comment:UserAgent."`
|
||||
Identifier string `gorm:"type:varchar(255);unique;index:idx_identifier;default:'';comment:Device Identifier"`
|
||||
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"`
|
||||
Enabled bool `gorm:"default:true;not null;comment:Enabled"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
|
||||
func (*Device) TableName() string {
|
||||
|
||||
@ -637,11 +637,12 @@ type DeviceAuthticateConfig struct {
|
||||
}
|
||||
|
||||
type DeviceLoginRequest struct {
|
||||
Identifier string `json:"identifier" validate:"required"`
|
||||
IP string `header:"X-Original-Forwarded-For"`
|
||||
UserAgent string `json:"user_agent" validate:"required"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
ShortCode string `json:"short_code,optional"`
|
||||
Identifier string `json:"identifier" validate:"required"`
|
||||
IP string `header:"X-Original-Forwarded-For"`
|
||||
UserAgent string `json:"user_agent" validate:"required"`
|
||||
CfToken string `json:"cf_token,optional"`
|
||||
ShortCode string `json:"short_code,optional"`
|
||||
BasePayload string `json:"base_payload,optional"`
|
||||
}
|
||||
|
||||
type DissolveFamilyRequest struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user