From cfa346fe6bb2df078a82ab587e8e895d8ade13fa Mon Sep 17 00:00:00 2001 From: xiaowu <44340137+wang-xiaowu@users.noreply.github.com> Date: Thu, 9 Nov 2023 22:41:46 +0800 Subject: [PATCH] feature add (#270) --- config.yml | 4 +++- config/config.go | 19 ++++++++++--------- logic/a_logic.go | 7 ++++++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/config.yml b/config.yml index 1a7a1d7..259a4c1 100644 --- a/config.yml +++ b/config.yml @@ -107,6 +107,8 @@ ldap: group-name-modify: false # 是否允许更改用户DN user-name-modify: false + # 默认邮箱后缀 + default-email-suffix: "eryajf.net" # 📢 即便用不到如下三段配置信息,也不要删除,否则会有一些奇怪的错误出现 dingtalk: # 配置获取详细文档参考: http://ldapdoc.eryajf.net/pages/94f43a/ @@ -143,4 +145,4 @@ feishu: dept-list: # 配置要同步的部门列表,配置留空则同步所有部门,在开头加^表示不同步此部门 #- "48456726" # 需要同步的部门ID #- "^61213417" # 不需要同步的部门ID - is-update-syncd: false # 当飞书用户的邮箱,手机号,部门等信息更新之后,是否同步更新,默认为false,如果你不了解这个字段的含义,则不建议开启 \ No newline at end of file + is-update-syncd: false # 当飞书用户的邮箱,手机号,部门等信息更新之后,是否同步更新,默认为false,如果你不了解这个字段的含义,则不建议开启 diff --git a/config/config.go b/config/config.go index 3f930f8..0b67b23 100644 --- a/config/config.go +++ b/config/config.go @@ -140,15 +140,16 @@ type RateLimitConfig struct { } type LdapConfig struct { - Url string `mapstructure:"url" json:"url"` - MaxConn int `mapstructure:"max-conn" json:"maxConn"` - BaseDN string `mapstructure:"base-dn" json:"baseDN"` - AdminDN string `mapstructure:"admin-dn" json:"adminDN"` - AdminPass string `mapstructure:"admin-pass" json:"adminPass"` - UserDN string `mapstructure:"user-dn" json:"userDN"` - UserInitPassword string `mapstructure:"user-init-password" json:"userInitPassword"` - GroupNameModify bool `mapstructure:"group-name-modify" json:"groupNameModify"` - UserNameModify bool `mapstructure:"user-name-modify" json:"userNameModify"` + Url string `mapstructure:"url" json:"url"` + MaxConn int `mapstructure:"max-conn" json:"maxConn"` + BaseDN string `mapstructure:"base-dn" json:"baseDN"` + AdminDN string `mapstructure:"admin-dn" json:"adminDN"` + AdminPass string `mapstructure:"admin-pass" json:"adminPass"` + UserDN string `mapstructure:"user-dn" json:"userDN"` + UserInitPassword string `mapstructure:"user-init-password" json:"userInitPassword"` + GroupNameModify bool `mapstructure:"group-name-modify" json:"groupNameModify"` + UserNameModify bool `mapstructure:"user-name-modify" json:"userNameModify"` + DefaultEmailSuffix string `mapstructure:"default-email-suffix" json:"defaultEmailSuffix"` } type EmailConfig struct { Host string `mapstructure:"host" json:"host"` diff --git a/logic/a_logic.go b/logic/a_logic.go index 87f1ba6..26daacc 100644 --- a/logic/a_logic.go +++ b/logic/a_logic.go @@ -96,7 +96,12 @@ func CommonAddUser(user *model.User, groups []*model.Group) error { user.Introduction = user.Nickname } if user.Mail == "" { - user.Mail = user.Username + "@eryajf.net" + // 兼容 + if len(config.Conf.Ldap.DefaultEmailSuffix) > 0 { + user.Mail = user.Username + "@" + config.Conf.Ldap.DefaultEmailSuffix + } else { + user.Mail = user.Username + "@eryajf.net" + } } if user.JobNumber == "" { user.JobNumber = "0000"