feat: 用户管理列表增加来源字段(auth_source),支持本地/LDAP筛选

This commit is contained in:
hermes-$(hostname) committed 2026-05-29 17:05:56 +00:00
1 parent ac07e6ef38
commit 8384006ae9
5 files changed
+196 -117

No files matched your search

+1
View File
@@ -75,6 +75,7 @@ func Login(c *gin.Context) {
DisplayName: ldapInfo.DisplayName,
Email: ldapInfo.Email,
HashedPassword: "-", // LDAP 用户不存本地密码
AuthSource: "ldap",
Role: defaultRole,
IsActive: &isActive,
}
+33 -1
View File
@@ -488,7 +488,39 @@ func BatchImportLDAP(c *gin.Context) {
// POST /api/v1/ldap-config/delete-user
func DeleteLDAPUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "User deleted (placeholder)"})
var req struct {
DN string `json:"dn" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "缺少 dn 参数"})
return
}
var cfg model.LDAPConfig
if err := model.DB.Order("id").First(&cfg).Error; err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "LDAP 配置不存在"})
return
}
conn, err := dialLDAP(&cfg)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "LDAP 连接失败: " + err.Error()})
return
}
defer conn.Close()
adminPw, _ := decryptPassword(cfg.AdminPassword)
if err := conn.Bind(cfg.AdminDN, adminPw); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "LDAP 管理员绑定失败"})
return
}
if err := conn.Del(ldap.NewDelRequest(req.DN, nil)); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "删除用户失败: " + err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "用户已从 LDAP 删除"})
}
// helper: dial LDAP with config