feat: 用户管理列表增加来源字段(auth_source),支持本地/LDAP筛选
This commit is contained in:
1 parent
ac07e6ef38
commit
8384006ae9
5 files changed
+196
-117
No files matched your search
@@ -75,6 +75,7 @@ func Login(c *gin.Context) {
|
||||
DisplayName: ldapInfo.DisplayName,
|
||||
Email: ldapInfo.Email,
|
||||
HashedPassword: "-", // LDAP 用户不存本地密码
|
||||
AuthSource: "ldap",
|
||||
Role: defaultRole,
|
||||
IsActive: &isActive,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,6 +16,7 @@ type User struct {
|
||||
Email *string `gorm:"size:100" json:"email"`
|
||||
Phone *string `gorm:"size:20" json:"phone"`
|
||||
HashedPassword string `gorm:"size:200;not null" json:"-"`
|
||||
AuthSource string `gorm:"size:20;default:'local'" json:"auth_source"` // local / ldap
|
||||
Role string `gorm:"size:20;not null" json:"role"` // admin, dba, developer, auditor
|
||||
IsActive *bool `gorm:"default:true" json:"is_active"`
|
||||
Preferences *string `gorm:"type:text" json:"preferences"` // JSON: {"theme":"dark","login_style":"split"}
|
||||
|
||||
Reference in new issue
Block a user