Add VerificationStatusNone constant and update converter to return general identity with none status instead of empty strings when user has not applied for verification.
118 lines
4.4 KiB
Go
118 lines
4.4 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// UserStatus 用户状态
|
|
type UserStatus string
|
|
|
|
const (
|
|
UserStatusActive UserStatus = "active"
|
|
UserStatusBanned UserStatus = "banned"
|
|
UserStatusInactive UserStatus = "inactive"
|
|
UserStatusPendingDeletion UserStatus = "pending_deletion"
|
|
)
|
|
|
|
// VisibilityLevel 可见性级别
|
|
type VisibilityLevel string
|
|
|
|
const (
|
|
VisibilityEveryone VisibilityLevel = "everyone"
|
|
VisibilityFollowing VisibilityLevel = "following"
|
|
VisibilitySelf VisibilityLevel = "self"
|
|
)
|
|
|
|
// PrivacySettings 隐私设置
|
|
type PrivacySettings struct {
|
|
FollowersVisibility VisibilityLevel `json:"followers_visibility" gorm:"type:varchar(20);default:everyone"`
|
|
FollowingVisibility VisibilityLevel `json:"following_visibility" gorm:"type:varchar(20);default:everyone"`
|
|
PostsVisibility VisibilityLevel `json:"posts_visibility" gorm:"type:varchar(20);default:everyone"`
|
|
FavoritesVisibility VisibilityLevel `json:"favorites_visibility" gorm:"type:varchar(20);default:everyone"`
|
|
}
|
|
|
|
// UserIdentity 用户身份类型
|
|
type UserIdentity string
|
|
|
|
const (
|
|
UserIdentityGeneral UserIdentity = "general" // 普通用户
|
|
UserIdentityStudent UserIdentity = "student" // 学生
|
|
UserIdentityTeacher UserIdentity = "teacher" // 教师
|
|
UserIdentityStaff UserIdentity = "staff" // 职工
|
|
UserIdentityAlumni UserIdentity = "alumni" // 校友
|
|
UserIdentityExternal UserIdentity = "external" // 外部人员
|
|
)
|
|
|
|
// VerificationStatus 审核状态
|
|
type VerificationStatus string
|
|
|
|
const (
|
|
VerificationStatusNotSubmitted VerificationStatus = "not_submitted" // 未提交
|
|
VerificationStatusPending VerificationStatus = "pending" // 审核中
|
|
VerificationStatusApproved VerificationStatus = "approved" // 已通过
|
|
VerificationStatusRejected VerificationStatus = "rejected" // 已拒绝
|
|
VerificationStatusNone VerificationStatus = "none" // 无认证(对外展示用)
|
|
)
|
|
|
|
// User 用户实体
|
|
type User struct {
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
|
Username string `json:"username" gorm:"type:varchar(50);uniqueIndex;not null"`
|
|
Nickname string `json:"nickname" gorm:"type:varchar(100);not null"`
|
|
Email *string `json:"email" gorm:"type:varchar(255);uniqueIndex"`
|
|
Phone *string `json:"phone" gorm:"type:varchar(20);uniqueIndex"`
|
|
EmailVerified bool `json:"email_verified" gorm:"default:false"`
|
|
PasswordHash string `json:"-" gorm:"type:varchar(255);not null"`
|
|
Avatar string `json:"avatar" gorm:"type:text"`
|
|
CoverURL string `json:"cover_url" gorm:"type:text"` // 头图URL
|
|
Bio string `json:"bio" gorm:"type:text"`
|
|
Website string `json:"website" gorm:"type:varchar(255)"`
|
|
Location string `json:"location" gorm:"type:varchar(100)"`
|
|
|
|
// 实名认证信息(可选)
|
|
RealName string `json:"real_name" gorm:"type:varchar(100)"` // 真实姓名
|
|
IDCard string `json:"-" gorm:"type:varchar(18)"` // 身份证号(加密存储)
|
|
IsVerified bool `json:"is_verified" gorm:"default:false"` // 是否实名认证
|
|
VerifiedAt *time.Time `json:"verified_at" gorm:"type:timestamp"`
|
|
|
|
// 统计计数
|
|
PostsCount int `json:"posts_count" gorm:"default:0"`
|
|
FollowersCount int `json:"followers_count" gorm:"default:0"`
|
|
FollowingCount int `json:"following_count" gorm:"default:0"`
|
|
|
|
// 身份认证
|
|
Identity UserIdentity `json:"identity" gorm:"type:varchar(20);default:general"`
|
|
VerificationStatus VerificationStatus `json:"verification_status" gorm:"type:varchar(20);default:not_submitted"`
|
|
|
|
// 状态
|
|
Status UserStatus `json:"status" gorm:"type:varchar(20);default:active"`
|
|
LastLoginAt *time.Time `json:"last_login_at" gorm:"type:timestamp"`
|
|
LastLoginIP string `json:"last_login_ip" gorm:"type:varchar(45)"`
|
|
|
|
// 账号注销
|
|
DeletionRequestedAt *time.Time `json:"deletion_requested_at" gorm:"type:timestamp"`
|
|
|
|
// 隐私设置
|
|
PrivacySettings PrivacySettings `json:"privacy_settings" gorm:"embedded;embeddedPrefix:privacy_"`
|
|
|
|
// 时间戳
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
|
}
|
|
|
|
// BeforeCreate 创建前生成UUID
|
|
func (u *User) BeforeCreate(tx *gorm.DB) error {
|
|
if u.ID == "" {
|
|
u.ID = uuid.New().String()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|