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

@@ -0,0 +1,35 @@
package middleware
import (
"github.com/gin-gonic/gin"
"carrot_bbs/internal/model"
"carrot_bbs/internal/pkg/response"
"carrot_bbs/internal/repository"
)
func RequireVerification(userRepo repository.UserRepository) gin.HandlerFunc {
return func(c *gin.Context) {
userID, exists := c.Get("user_id")
if !exists {
response.Unauthorized(c, "未授权")
c.Abort()
return
}
user, err := userRepo.GetByID(userID.(string))
if err != nil {
response.HandleError(c, err, "获取用户信息失败")
c.Abort()
return
}
if user.VerificationStatus != model.VerificationStatusApproved {
response.Forbidden(c, "需要完成身份认证")
c.Abort()
return
}
c.Next()
}
}