feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
|
|
|
|
// StrPtr 将 string 转为 *string(空字符串返回 nil,用于可选的 unique 字段)
|
|
|
|
|
|
func StrPtr(s string) *string {
|
|
|
|
|
|
if s == "" {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &s
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DerefStr 安全解引用 *string,nil 返回空字符串
|
|
|
|
|
|
func DerefStr(s *string) string {
|
|
|
|
|
|
if s == nil {
|
|
|
|
|
|
return ""
|
|
|
|
|
|
}
|
|
|
|
|
|
return *s
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gender 性别
|
|
|
|
|
|
type Gender int
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
GenderUnknown Gender = iota // 未知
|
|
|
|
|
|
GenderMale // 男
|
|
|
|
|
|
GenderFemale // 女
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// UserStatus 用户状态
|
|
|
|
|
|
type UserStatus int
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
UserStatusInactive UserStatus = 0 // 未激活
|
|
|
|
|
|
UserStatusActive UserStatus = 1 // 已激活
|
|
|
|
|
|
UserStatusLocked UserStatus = 2 // 已锁定
|
|
|
|
|
|
UserStatusDisabled UserStatus = 3 // 已禁用
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// User 用户模型
|
|
|
|
|
|
type User struct {
|
test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
2026-04-17 20:43:50 +08:00
|
|
|
|
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
|
|
|
|
Username string `gorm:"type:varchar(50);uniqueIndex;not null" json:"username"`
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
|
// Email/Phone 使用指针类型:nil 存储为 NULL,允许多个用户没有邮箱/手机(唯一约束对 NULL 不生效)
|
|
|
|
|
|
Email *string `gorm:"type:varchar(100);uniqueIndex" json:"email"`
|
|
|
|
|
|
Phone *string `gorm:"type:varchar(20);uniqueIndex" json:"phone"`
|
|
|
|
|
|
Nickname string `gorm:"type:varchar(50)" json:"nickname"`
|
|
|
|
|
|
Avatar string `gorm:"type:varchar(255)" json:"avatar"`
|
|
|
|
|
|
Password string `gorm:"type:varchar(255)" json:"-"`
|
|
|
|
|
|
Gender Gender `gorm:"type:int;default:0" json:"gender"`
|
|
|
|
|
|
Birthday *time.Time `gorm:"type:date" json:"birthday,omitempty"`
|
|
|
|
|
|
Region string `gorm:"type:varchar(50)" json:"region"`
|
|
|
|
|
|
Bio string `gorm:"type:varchar(500)" json:"bio"`
|
test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
2026-04-17 20:43:50 +08:00
|
|
|
|
Status UserStatus `gorm:"type:int;default:0;index;index:idx_users_status_created_at" json:"status"`
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
|
LastLoginTime *time.Time `json:"last_login_time,omitempty"`
|
|
|
|
|
|
LastLoginIP string `gorm:"type:varchar(50)" json:"last_login_ip"`
|
test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
2026-04-17 20:43:50 +08:00
|
|
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_users_status_created_at" json:"created_at"`
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
|
|
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
|
|
|
|
|
|
|
|
|
|
|
|
// 2FA / TOTP 字段
|
|
|
|
|
|
TOTPEnabled bool `gorm:"default:false" json:"totp_enabled"`
|
test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
2026-04-17 20:43:50 +08:00
|
|
|
|
TOTPSecret string `gorm:"type:varchar(64)" json:"-"` // Base32 密钥,不返回给前端
|
|
|
|
|
|
TOTPRecoveryCodes string `gorm:"type:text" json:"-"` // JSON 编码的恢复码列表
|
2026-04-18 15:33:12 +08:00
|
|
|
|
|
|
|
|
|
|
// PasswordChangedAt 密码更新时间,用于 token 失效机制
|
|
|
|
|
|
PasswordChangedAt time.Time `gorm:"type:timestamp;index" json:"password_changed_at,omitempty"`
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TableName 指定表名
|
|
|
|
|
|
func (User) TableName() string {
|
|
|
|
|
|
return "users"
|
|
|
|
|
|
}
|