后端改进: - 修复 dashboard/recent-alerts 的 limit 参数解析 (原代码错误地将数字解析为日期) - 为 dashboard/recent-releases 添加 limit 参数解析支持 - 新增 generateAppReleases 种子数据生成函数 (10条应用发布记录) - 修复 AlertEvent 的 rule_name/rule_id/severity 数据一致性 - 添加 go-ldap/ldap/v3 依赖并集成 LDAP 认证处理器 - 添加 seed.go 自动种子数据初始化 (admin用户+LDAP配置) - User model 添加 AuthSource/LDAPConfig 字段 前端改进: - 修复 User 类型定义以匹配后端 API (real_name/is_admin/auth_source等) - 修复 Header.tsx 的 real_name 属性引用导致 TypeScript 编译错误 - 统一 API 服务层、暗色主题样式、组件联调优化 验证: - go build ./... 编译通过 - npm run build 构建通过 - 仪表盘发布历史、告警消息等区域数据正常展示 - 健康检查 /health 正常
130 lines
4.5 KiB
Go
130 lines
4.5 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// User 用户模型
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
|
Password string `gorm:"size:255;not null" json:"-"`
|
|
Email string `gorm:"size:128" json:"email"`
|
|
Phone string `gorm:"size:32" json:"phone"`
|
|
RealName string `gorm:"size:64" json:"real_name"`
|
|
Avatar string `gorm:"size:255" json:"avatar"`
|
|
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
|
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
|
AuthSource string `gorm:"size:20;default:'local'" json:"auth_source"` // local / ldap
|
|
LastLogin *time.Time `json:"last_login"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// 关联
|
|
Roles []Role `gorm:"many2many:user_roles;" json:"roles,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|
|
|
|
// Role 角色模型
|
|
type Role struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:255" json:"description"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// 关联
|
|
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Role) TableName() string {
|
|
return "roles"
|
|
}
|
|
|
|
// Permission 权限模型
|
|
type Permission struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;not null" json:"name"`
|
|
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
|
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
|
Path string `gorm:"size:255" json:"path"`
|
|
Method string `gorm:"size:32" json:"method"`
|
|
ParentID *uint `json:"parent_id"`
|
|
Sort int `gorm:"default:0" json:"sort"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Permission) TableName() string {
|
|
return "permissions"
|
|
}
|
|
|
|
// LoginRequest 登录请求
|
|
type LoginRequest struct {
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
// LoginResponse 登录响应
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
ExpiresIn int `json:"expires_in"`
|
|
User *User `json:"user"`
|
|
}
|
|
|
|
// CreateUserRequest 创建用户请求
|
|
type CreateUserRequest struct {
|
|
Username string `json:"username" binding:"required,min=3,max=64"`
|
|
Password string `json:"password" binding:"required,min=6,max=32"`
|
|
Email string `json:"email" binding:"required,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// UpdateUserRequest 更新用户请求
|
|
type UpdateUserRequest struct {
|
|
Email string `json:"email" binding:"omitempty,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
Status *int `json:"status"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// ChangePasswordRequest 修改密码请求
|
|
type ChangePasswordRequest struct {
|
|
OldPassword string `json:"old_password" binding:"required"`
|
|
NewPassword string `json:"new_password" binding:"required,min=6,max=32"`
|
|
}
|
|
|
|
// LDAPConfig LDAP配置
|
|
type LDAPConfig struct {
|
|
ID int `gorm:"primarykey" json:"id"`
|
|
LDAPHost string `gorm:"size:200;not null" json:"ldap_host"`
|
|
LDAPPort *int `json:"ldap_port"`
|
|
UseLDAPS *bool `json:"use_ldaps"`
|
|
AdminDN string `gorm:"size:500;not null" json:"admin_dn"`
|
|
AdminPassword string `gorm:"size:500;not null" json:"admin_password"`
|
|
SearchFilter *string `gorm:"size:500" json:"search_filter"`
|
|
BaseDN string `gorm:"size:500;not null" json:"base_dn"`
|
|
UserMapping *string `gorm:"type:text" json:"user_mapping"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (LDAPConfig) TableName() string { return "ldap_configs" }
|