Skip to content

Commit

Permalink
fix: 如果没有邮箱或手机号则以一种不重复的方案进行处理 (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
eryajf authored Apr 25, 2023
1 parent 9e18a5c commit 2654e77
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions logic/a_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package logic

import (
"fmt"
"math/rand"
"time"

"github.com/eryajf/go-ldap-admin/config"
"github.com/eryajf/go-ldap-admin/model"
"github.com/eryajf/go-ldap-admin/public/common"
Expand Down Expand Up @@ -93,7 +96,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
user.Introduction = user.Nickname
}
if user.Mail == "" {
user.Mail = "noone@eryajf.net"
user.Mail = user.Username + "@eryajf.net"
}
if user.JobNumber == "" {
user.JobNumber = "0000"
Expand All @@ -108,7 +111,7 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
user.PostalAddress = "默认:地球"
}
if user.Mobile == "" {
user.Mobile = "18888888888"
user.Mobile = generateMobile()
}

// 先将用户添加到MySQL
Expand Down Expand Up @@ -406,3 +409,13 @@ func groupListToTree(rootGroup *model.Group, list []*model.Group) []*model.Group
}
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)
}

0 comments on commit 2654e77

Please sign in to comment.