feat: token/add接口增加login_name参数, update接口也支持修改login_name

This commit is contained in:
ShenQiLun 2026-06-30 13:37:00 +08:00
parent ab448f6fbc
commit 0f029b9ba6

View File

@ -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 批量添加TokenJSON数组: [{"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")