mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Refactor out GenerateIdForNewUser()
This commit is contained in:
@ -16,6 +16,7 @@ package object
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/casdoor/casdoor/conf"
|
||||
@ -483,7 +484,7 @@ func GetMaskedUsers(users []*User, errs ...error) ([]*User, error) {
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func GetLastUser(owner string) (*User, error) {
|
||||
func getLastUser(owner string) (*User, error) {
|
||||
user := User{Owner: owner}
|
||||
existed, err := ormer.Engine.Desc("created_time", "id").Get(&user)
|
||||
if err != nil {
|
||||
@ -900,3 +901,22 @@ func (user *User) IsGlobalAdmin() bool {
|
||||
|
||||
return user.Owner == "built-in"
|
||||
}
|
||||
|
||||
func GenerateIdForNewUser(application *Application) (string, error) {
|
||||
if application.GetSignupItemRule("ID") != "Incremental" {
|
||||
return util.GenerateId(), nil
|
||||
}
|
||||
|
||||
lastUser, err := getLastUser(application.Organization)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
lastUserId := -1
|
||||
if lastUser != nil {
|
||||
lastUserId = util.ParseInt(lastUser.Id)
|
||||
}
|
||||
|
||||
res := strconv.Itoa(lastUserId + 1)
|
||||
return res, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user