feat: add short_code field to device login API

- Add optional short_code parameter to DeviceLoginRequest
- Add ShortCode field to Device model
- Save short_code to database during device registration
- Add database migration for user_device.short_code column
- Fix duplicate variable declaration in routes.go
This commit is contained in:
EUForest 2026-01-10 18:11:24 +08:00
parent ed669d0620
commit 3359704a45
7 changed files with 10 additions and 2 deletions

View File

@ -124,6 +124,7 @@ type (
IP string `header:"X-Original-Forwarded-For"` IP string `header:"X-Original-Forwarded-For"`
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"`
} }
) )

View File

@ -0,0 +1,2 @@
-- Remove short_code column from user_device table
ALTER TABLE `user_device` DROP COLUMN `short_code`;

View File

@ -0,0 +1,2 @@
-- Add short_code column to user_device table
ALTER TABLE `user_device` ADD COLUMN `short_code` VARCHAR(255) DEFAULT '' COMMENT 'Short Code' AFTER `identifier`;

View File

@ -939,10 +939,10 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
serverGroupRouter.GET("/user", server.GetServerUserListHandler(serverCtx)) serverGroupRouter.GET("/user", server.GetServerUserListHandler(serverCtx))
} }
serverV2GroupRouter := router.Group("/v2/server") serverGroupRouterV2 := router.Group("/v2/server")
{ {
// Get Server Protocol Config // Get Server Protocol Config
serverV2GroupRouter.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx)) serverGroupRouterV2.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx))
} }
} }

View File

@ -197,6 +197,7 @@ func (l *DeviceLoginLogic) registerUserAndDevice(req *types.DeviceLoginRequest)
UserId: userInfo.Id, UserId: userInfo.Id,
UserAgent: req.UserAgent, UserAgent: req.UserAgent,
Identifier: req.Identifier, Identifier: req.Identifier,
ShortCode: req.ShortCode,
Enabled: true, Enabled: true,
Online: false, Online: false,
} }

View File

@ -81,6 +81,7 @@ type Device struct {
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"` UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
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"`
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

@ -558,6 +558,7 @@ type DeviceLoginRequest struct {
IP string `header:"X-Original-Forwarded-For"` IP string `header:"X-Original-Forwarded-For"`
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"`
} }
type Document struct { type Document struct {