Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}