二阶段差不多

This commit is contained in:
2026-06-01 19:46:51 +08:00
parent 9e50d05e71
commit 4e233c82b4
34 changed files with 1631 additions and 67 deletions
+26
View File
@@ -0,0 +1,26 @@
package middleware
import (
"net/http"
"mail_go/internal/store"
"github.com/gin-gonic/gin"
)
// BanMiddleware checks if the client IP is currently banned.
// If banned, it renders the "banned" template and aborts the request.
func BanMiddleware(stores *store.Stores) gin.HandlerFunc {
return func(c *gin.Context) {
ip := c.ClientIP()
banned, entry := stores.Bans.IsBanned(ip)
if banned {
c.HTML(http.StatusForbidden, "banned", gin.H{
"entry": entry,
})
c.Abort()
return
}
c.Next()
}
}