feat(verification): add user identity verification system
Some checks failed
Build Backend / build (push) Successful in 7m12s
Build Backend / build-docker (push) Has been cancelled

Implement a complete user identity verification system with support for multiple identity types (student, teacher, staff, alumni). The system includes user-facing verification submission and status checking endpoints, admin endpoints for reviewing verification requests, middleware for protecting verification-required routes, and integration with the user model to track verification status.
This commit is contained in:
lafay
2026-04-05 20:27:03 +08:00
parent b640c9a249
commit 6429322217
17 changed files with 977 additions and 75 deletions

View File

@@ -170,6 +170,9 @@ func autoMigrate(db *gorm.DB) error {
// 通话相关
&CallSession{},
&CallParticipant{},
// 身份认证相关
&VerificationRecord{},
)
if err != nil {
return err

View File

@@ -16,6 +16,28 @@ const (
UserStatusInactive UserStatus = "inactive"
)
// 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" // 已拒绝
)
// User 用户实体
type User struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
@@ -42,6 +64,10 @@ type User struct {
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"`

View File

@@ -0,0 +1,40 @@
package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type VerificationRecord struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
UserID string `json:"user_id" gorm:"type:varchar(36);index;not null"`
Identity UserIdentity `json:"identity" gorm:"type:varchar(20);not null"`
Status VerificationStatus `json:"status" gorm:"type:varchar(20);default:pending"`
RealName string `json:"real_name" gorm:"type:varchar(100)"`
StudentID string `json:"student_id" gorm:"type:varchar(50)"`
EmployeeID string `json:"employee_id" gorm:"type:varchar(50)"`
Department string `json:"department" gorm:"type:varchar(200)"`
ProofMaterials string `json:"proof_materials" gorm:"type:text"`
ReviewedAt *time.Time `json:"reviewed_at" gorm:"type:timestamp"`
ReviewedBy *string `json:"reviewed_by" gorm:"type:varchar(36)"`
RejectReason string `json:"reject_reason" gorm:"type:text"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
func (v *VerificationRecord) BeforeCreate(tx *gorm.DB) error {
if v.ID == "" {
v.ID = uuid.New().String()
}
return nil
}
func (VerificationRecord) TableName() string {
return "verification_records"
}