mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
feat: add regex support for account item (#2714)
* feat: add regex support for account item * feat: use reflect to process user field * fix: fix lint problem * feat: improve code format and fix reflect error
This commit is contained in:
@ -15,7 +15,9 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -221,6 +223,26 @@ type ManagedAccount struct {
|
||||
SigninUrl string `xorm:"varchar(200)" json:"signinUrl"`
|
||||
}
|
||||
|
||||
func GetUserFieldStringValue(user *User, fieldName string) (bool, string, error) {
|
||||
val := reflect.ValueOf(*user)
|
||||
fieldValue := val.FieldByName(fieldName)
|
||||
|
||||
if !fieldValue.IsValid() {
|
||||
return false, "", nil
|
||||
}
|
||||
|
||||
if fieldValue.Kind() == reflect.String {
|
||||
return true, fieldValue.String(), nil
|
||||
}
|
||||
|
||||
marshalValue, err := json.Marshal(fieldValue.Interface())
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
|
||||
return true, string(marshalValue), nil
|
||||
}
|
||||
|
||||
func GetGlobalUserCount(field, value string) (int64, error) {
|
||||
session := GetSession("", -1, -1, field, value, "", "")
|
||||
return session.Count(&User{})
|
||||
|
Reference in New Issue
Block a user