feat: 更新SproutGate前后端代码

This commit is contained in:
2026-04-01 22:04:01 +08:00
parent 90590c7cb0
commit 650e1c7707
49 changed files with 3609 additions and 768 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/gin-gonic/gin"
"sproutgate-backend/internal/auth"
"sproutgate-backend/internal/models"
)
@@ -54,13 +55,22 @@ func verifyCode(code string, hash string) bool {
}
func writeBanJSON(c *gin.Context, reason string) {
h := gin.H{"error": "account is banned"}
h := gin.H{"error": "account is banned", "valid": false}
if r := strings.TrimSpace(reason); r != "" {
h["banReason"] = r
}
c.JSON(http.StatusForbidden, h)
}
// abortIfTokenEpochStale 若 JWT 内 epoch 与用户当前 token_epoch 不一致,则拒绝(例如管理员已封禁并递增 epoch
func abortIfTokenEpochStale(c *gin.Context, claims *auth.Claims, u models.UserRecord) bool {
if claims.TokenEpoch == u.TokenEpoch {
return false
}
c.JSON(http.StatusUnauthorized, gin.H{"valid": false, "error": "token revoked"})
return true
}
func abortIfUserBanned(c *gin.Context, u models.UserRecord) bool {
if !u.Banned {
return false