yanlongqi 3ecc1c6a18 添加用户管理功能
新增功能:
- 用户管理页面:展示所有用户及答题统计
- 用户详情页面:查看单个用户的详细答题数据
- 管理员权限中间件:仅yanlongqi用户可访问
- 后端API接口:用户列表和详情统计

后端更新:
- 新增 admin_handler.go:用户管理相关处理器
- 新增 admin.go 中间件:管理员权限验证
- 新增 user_stats.go 模型:用户统计数据结构
- 更新 main.go:注册用户管理API路由

前端更新:
- 新增 UserManagement 页面:用户列表和统计卡片
- 新增 UserDetail 页面:用户详细信息和题型统计
- 更新 Home 页面:添加用户管理入口(仅管理员可见)
- 更新 App.tsx:添加用户管理路由和权限保护
- 更新 API 接口:添加用户管理相关接口定义

UI优化:
- 用户管理页面标题居中显示,参考错题本设计
- 统计卡片使用16px padding
- 返回按钮使用绝对定位,标题居中
- 字体大小统一为18px,字重700

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 06:21:15 +08:00

37 lines
772 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
// AdminOnly 管理员权限验证中间件仅yanlongqi用户可访问
func AdminOnly() gin.HandlerFunc {
return func(c *gin.Context) {
// 从上下文中获取用户名需要先通过Auth中间件
username, exists := c.Get("username")
if !exists {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"message": "未登录",
})
c.Abort()
return
}
// 检查是否是管理员用户仅yanlongqi
if username != "yanlongqi" {
c.JSON(http.StatusForbidden, gin.H{
"success": false,
"message": "无权访问,该功能仅限管理员使用",
})
c.Abort()
return
}
// 权限验证通过,继续处理请求
c.Next()
}
}