Skip to content

Commit 2654e77

Browse files
authored
fix: 如果没有邮箱或手机号则以一种不重复的方案进行处理 (#206)
1 parent 9e18a5c commit 2654e77

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

logic/a_logic.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package logic
22

33
import (
44
"fmt"
5+
"math/rand"
6+
"time"
7+
58
"github.com/eryajf/go-ldap-admin/config"
69
"github.com/eryajf/go-ldap-admin/model"
710
"github.com/eryajf/go-ldap-admin/public/common"
@@ -93,7 +96,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
9396
user.Introduction = user.Nickname
9497
}
9598
if user.Mail == "" {
96-
user.Mail = "noone@eryajf.net"
99+
user.Mail = user.Username + "@eryajf.net"
97100
}
98101
if user.JobNumber == "" {
99102
user.JobNumber = "0000"
@@ -108,7 +111,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
108111
user.PostalAddress = "默认:地球"
109112
}
110113
if user.Mobile == "" {
111-
user.Mobile = "18888888888"
114+
user.Mobile = generateMobile()
112115
}
113116

114117
// 先将用户添加到MySQL
@@ -406,3 +409,13 @@ func groupListToTree(rootGroup *model.Group, list []*model.Group) []*model.Group
406409
}
407410
return children
408411
}
412+
413+
func generateMobile() string {
414+
rand.Seed(time.Now().UnixNano())
415+
randNum := rand.Intn(9000000000) + 1000000000
416+
randNum = randNum + 10000000000
417+
if isql.User.Exist(tools.H{"mobile": randNum}) {
418+
generateMobile()
419+
}
420+
return fmt.Sprintf("%v", randNum)
421+
}

0 commit comments

Comments
 (0)