From 0f029b9ba6ac81239e0c9c8b9c230c7df51bac9a Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Tue, 30 Jun 2026 13:37:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20token/add=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0login=5Fname=E5=8F=82=E6=95=B0,=20update=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B9=9F=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9login=5Fn?= =?UTF-8?q?ame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/token_handler.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/handler/token_handler.go b/internal/handler/token_handler.go index 52ef7f8..5663cdf 100644 --- a/internal/handler/token_handler.go +++ b/internal/handler/token_handler.go @@ -30,8 +30,9 @@ type TokenResponse struct { // TokenInput Token输入结构 type TokenInput struct { - Username string `json:"username"` - Token string `json:"token"` + LoginName string `json:"login_name"` + Username string `json:"username"` + Token string `json:"token"` } // BatchAddTokens 批量添加Token(JSON数组: [{"username":"","token":""},...]) @@ -71,12 +72,12 @@ func (h *TokenHandler) BatchAddTokens(w http.ResponseWriter, r *http.Request) { continue } - id, err := h.tokenRepo.Insert("", input.Username, "", input.Token, true) + id, err := h.tokenRepo.Insert(input.LoginName, input.Username, "", input.Token, true) if err != nil { log.Printf("[Token/BatchAdd] 第%d条插入失败: username=%s, 错误=%v", i+1, input.Username, err) failed = append(failed, input) } else { - log.Printf("[Token/BatchAdd] 第%d条插入成功: id=%d, username=%s", i+1, id, input.Username) + log.Printf("[Token/BatchAdd] 第%d条插入成功: id=%d, login_name=%s, username=%s", i+1, id, input.LoginName, input.Username) } } @@ -179,6 +180,7 @@ func (h *TokenHandler) UpdateToken(w http.ResponseWriter, r *http.Request) { r.ParseForm() idStr := r.PostForm.Get("id") + loginName := r.PostForm.Get("login_name") username := r.PostForm.Get("username") token := r.PostForm.Get("token") isEnableStr := r.PostForm.Get("is_enable") @@ -195,8 +197,8 @@ func (h *TokenHandler) UpdateToken(w http.ResponseWriter, r *http.Request) { isEnable = false } - log.Printf("[Token/Update] 更新: id=%d, username=%s, is_enable=%v, 来源IP: %s", id, username, isEnable, clientIP) - err = h.tokenRepo.Update(id, "", username, "", token, isEnable) + log.Printf("[Token/Update] 更新: id=%d, login_name=%s, username=%s, is_enable=%v, 来源IP: %s", id, loginName, username, isEnable, clientIP) + err = h.tokenRepo.Update(id, loginName, username, "", token, isEnable) if err != nil { log.Printf("[Token/Update] 更新失败: id=%d, 错误=%v, 来源IP: %s", id, err, clientIP) w.Header().Set("Content-Type", "application/json")