fix: 踢下线同时禁用账号防重连,禁止管理员踢自己

- handler/vpn.go: KickUserClient 踢线后设置 status=0 并失效所有会话,
  阻止客户端自动重连;新增自检,目标为当前管理员时返回 400
- AdminView.vue: handleKick 调用 API 前自检,自己则提示去修改密码
- zh.ts/en.ts: 新增 cannotKickSelf,更新 confirmKick 提示含禁用账号
This commit is contained in:
2026-07-10 13:33:04 +08:00
parent f94aa3c4ac
commit f6a1fb6288
4 changed files with 21 additions and 7 deletions
+12 -4
View File
@@ -421,11 +421,19 @@ func KickUserClient(c *gin.Context) {
return
}
if vpn.VPN == nil || !vpn.VPN.Running() {
c.JSON(http.StatusOK, gin.H{"message": "VPN 服务未运行", "kicked": 0})
currentUserID, _ := c.Get("user_id")
if uint(id) == currentUserID.(uint) {
c.JSON(http.StatusBadRequest, gin.H{"error": "不能踢自己下线,如需断开自己的设备请修改密码"})
return
}
n := vpn.VPN.KickUser(uint(id))
c.JSON(http.StatusOK, gin.H{"message": "已断开用户连接", "kicked": n})
n := 0
if vpn.VPN != nil && vpn.VPN.Running() {
n = vpn.VPN.KickUser(uint(id))
}
db.DB.Model(&user).Update("status", 0)
db.DB.Model(&model.Session{}).Where("user_id = ?", id).Update("invalid", true)
c.JSON(http.StatusOK, gin.H{"message": "已断开用户连接并禁用账号", "kicked": n})
}