This commit is contained in:
laodaming 2023-11-17 10:07:05 +08:00
parent cc1b2a657b
commit 62222bb781
2 changed files with 18 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/chinese_to_pinyin"
"fusenapi/utils/email"
"fusenapi/utils/ldap_lib"
"strings"
@ -46,8 +47,8 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, useri
if req.Password == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "密码不能为空")
}
if req.Email == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "邮箱不能为空")
if !email.IsEmailValid(req.Email) {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "邮箱格式不正确")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
//把用户名转pinyin

15
utils/email/verify.go Normal file
View File

@ -0,0 +1,15 @@
package email
import "regexp"
// 验证是否邮箱
func IsEmailValid(email string) bool {
// 邮箱正则表达式
regex := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
// 编译正则表达式
regexPattern := regexp.MustCompile(regex)
// 根据正则表达式验证邮箱
return regexPattern.MatchString(email)
}