fix: 如果没有邮箱或手机号则以一种不重复的方案进行处理 (#206)

This commit is contained in:
二丫讲梵 2023-04-25 23:10:43 +08:00 committed by GitHub
parent 9e18a5c08d
commit 2654e77e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -2,6 +2,9 @@ package logic
import ( import (
"fmt" "fmt"
"math/rand"
"time"
"github.com/eryajf/go-ldap-admin/config" "github.com/eryajf/go-ldap-admin/config"
"github.com/eryajf/go-ldap-admin/model" "github.com/eryajf/go-ldap-admin/model"
"github.com/eryajf/go-ldap-admin/public/common" "github.com/eryajf/go-ldap-admin/public/common"
@ -93,7 +96,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
user.Introduction = user.Nickname user.Introduction = user.Nickname
} }
if user.Mail == "" { if user.Mail == "" {
user.Mail = "noone@eryajf.net" user.Mail = user.Username + "@eryajf.net"
} }
if user.JobNumber == "" { if user.JobNumber == "" {
user.JobNumber = "0000" user.JobNumber = "0000"
@ -108,7 +111,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
user.PostalAddress = "默认:地球" user.PostalAddress = "默认:地球"
} }
if user.Mobile == "" { if user.Mobile == "" {
user.Mobile = "18888888888" user.Mobile = generateMobile()
} }
// 先将用户添加到MySQL // 先将用户添加到MySQL
@ -406,3 +409,13 @@ func groupListToTree(rootGroup *model.Group, list []*model.Group) []*model.Group
} }
return children return children
} }
func generateMobile() string {
rand.Seed(time.Now().UnixNano())
randNum := rand.Intn(9000000000) + 1000000000
randNum = randNum + 10000000000
if isql.User.Exist(tools.H{"mobile": randNum}) {
generateMobile()
}
return fmt.Sprintf("%v", randNum)
}