package handler import ( "fmt" "net/http" "strconv" "time" "xboard-go/internal/database" "xboard-go/internal/model" "github.com/gin-gonic/gin" ) // RealNameIndex renders the beautified plugin management page. func RealNameIndex(c *gin.Context) { var appNameSetting model.Setting database.DB.Where("name = ?", "app_name").First(&appNameSetting) appName := appNameSetting.Value if appName == "" { appName = "XBoard" } securePath := c.Param("path") apiEndpoint := fmt.Sprintf("/api/v1/%%s/realname/records", securePath) reviewEndpoint := fmt.Sprintf("/api/v1/%%s/realname/review", securePath) // We use %% for literal percent signs in Sprintf // and we avoid backticks in the JS code by using regular strings to remain compatible with Go raw strings. html := fmt.Sprintf(` %%s - 实名验证管理

实名验证管理

集中处理全站用户的身份验证申请

返回控制台
正在获取数据...
用户 ID 邮箱 真实姓名 认证状态 操作
操作成功
`, appName, securePath, apiEndpoint, reviewEndpoint) c.Header("Content-Type", "text/html; charset=utf-8") c.String(http.StatusOK, html) } // RealNameRecords handles the listing of authentication records. func RealNameRecords(c *gin.Context) { page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) pageSize := 15 keyword := c.Query("keyword") var records []model.RealNameAuth var total int64 query := database.DB.Preload("User").Model(&model.RealNameAuth{}) if keyword != "" { query = query.Joins("JOIN v2_user ON v2_user.id = v2_realname_auth.user_id"). Where("v2_user.email LIKE ?", "%%"+keyword+"%%") } query.Count(&total) query.Offset((page - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&records) lastPage := (total + int64(pageSize) - 1) / int64(pageSize) c.JSON(http.StatusOK, gin.H{ "data": records, "pagination": gin.H{ "total": total, "current": page, "last_page": lastPage, }, }) } // RealNameReview handles approval or rejection of a record. func RealNameReview(c *gin.Context) { id := c.Param("id") var req struct { Status string `json:"status" binding:"required"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"message": "参数错误"}) return } var record model.RealNameAuth if err := database.DB.First(&record, id).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"message": "记录不存在"}) return } record.Status = req.Status record.ReviewedAt = time.Now().Unix() database.DB.Save(&record) // Sync User Expiration if approved if req.Status == "approved" { // Set a long expiration date (e.g., 2099-12-31) expiry := time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC).Unix() database.DB.Model(&model.User{}).Where("id = ?", record.UserID).Update("expired_at", expiry) } c.JSON(http.StatusOK, gin.H{"message": "审核操作成功"}) }