- 登录链路改为用户名 + 密码 + 短信验证码 + DCAuth v2 设备签名 - 迁移 014:新增 login_sms_codes / user_devices / device_challenges 与 users.phone - 新增 /api/dcauth/authorize 与 challenge 状态轮询;旧密码登录仅放行未绑定手机号的账号 - 成员管理支持手机号绑定、设备重置、账号改名、昵称与重置密码 - 移除最后一个商户关系时软删除账号,释放用户名、手机号并撤销设备绑定
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 用户角色
|
|
const (
|
|
RoleAdmin = "admin" // 平台管理员
|
|
RoleMerchant = "merchant" // 商户账号
|
|
)
|
|
|
|
// User 系统用户
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// Username uniqueness is enforced by a partial database index for active
|
|
// accounts, allowing a username to be reused after its old account is soft deleted.
|
|
Username string `gorm:"size:64;not null" json:"username"`
|
|
PasswordHash string `gorm:"size:255;not null" json:"-"`
|
|
Nickname string `gorm:"size:64" json:"nickname"`
|
|
Role string `gorm:"size:32;not null;default:merchant" json:"role"`
|
|
Status int `gorm:"default:1" json:"status"` // 1启用 0禁用
|
|
|
|
// 登录安全:绑定手机号后强制走「密码 + 短信验证码 + DCAuth 设备签名」。
|
|
Phone string `gorm:"size:32;not null;default:''" json:"phone"`
|
|
PhoneBoundAt *time.Time `json:"phone_bound_at,omitempty"`
|
|
PhoneBoundBy *uint `json:"phone_bound_by,omitempty"`
|
|
|
|
// 以下字段只用于管理端列表展示,不落库到 users 表。
|
|
PhoneMasked string `gorm:"-" json:"phone_masked,omitempty"`
|
|
DeviceID string `gorm:"-" json:"device_id,omitempty"`
|
|
DeviceIDMasked string `gorm:"-" json:"device_id_masked,omitempty"`
|
|
DeviceBound bool `gorm:"-" json:"device_bound"`
|
|
}
|