Files
backend/internal/middleware/verification.go
lafay 2f584c1f2c
All checks were successful
Build Backend / build (push) Successful in 5m10s
Build Backend / build-docker (push) Successful in 2m22s
This is a breaking change that renames the entire project from "Carrot BBS" to "WithYou".
The Go module name has been changed from `carrot_bbs` to `with_you`, which requires
all import paths to be updated throughout the codebase and by external consumers.

BREAKING CHANGE: Module name changed from carrot_bbs to with_you. All imports
and dependencies must be updated from carrot_bbs/* to with_you/*.
2026-04-22 16:01:59 +08:00

38 lines
776 B
Go

package middleware
import (
"net/http"
"with_you/internal/model"
"with_you/internal/pkg/response"
"with_you/internal/repository"
"github.com/gin-gonic/gin"
)
func RequireVerified(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.InternalServerError(c, "获取用户信息失败")
c.Abort()
return
}
if user.VerificationStatus != model.VerificationStatusApproved {
response.ErrorWithStringCode(c, http.StatusForbidden, "VERIFICATION_REQUIRED", "请先完成身份认证")
c.Abort()
return
}
c.Next()
}
}