|
@@ -47,9 +47,10 @@ type UserAccount struct {
|
|
|
|
|
|
//syncorizeUserReturnInterface not designed to be used outside
|
|
|
type syncorizeUserReturnInterface struct {
|
|
|
- Userinfo []UserAccount `json:"userinfo"`
|
|
|
- Length int `json:"length"`
|
|
|
- Error string `json:"error"`
|
|
|
+ Userinfo []UserAccount `json:"userinfo"`
|
|
|
+ TotalLength int `json:"total_length"`
|
|
|
+ Length int `json:"length"`
|
|
|
+ Error string `json:"error"`
|
|
|
}
|
|
|
|
|
|
//NewLdapHandler xxx
|
|
@@ -175,12 +176,12 @@ func (ldap *ldapHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//@para limit: -1 means unlimited
|
|
|
-func (ldap *ldapHandler) getAllUser(limit int) ([]UserAccount, error) {
|
|
|
+func (ldap *ldapHandler) getAllUser(limit int) ([]UserAccount, int, error) {
|
|
|
//read the user account from ldap, if limit is -1 then it will read all USERS
|
|
|
var accounts []UserAccount
|
|
|
result, err := ldap.ldapreader.GetAllUser()
|
|
|
if err != nil {
|
|
|
- return []UserAccount{}, err
|
|
|
+ return []UserAccount{}, 0, err
|
|
|
}
|
|
|
//loop through the result
|
|
|
for i, v := range result {
|
|
@@ -192,9 +193,9 @@ func (ldap *ldapHandler) getAllUser(limit int) ([]UserAccount, error) {
|
|
|
}
|
|
|
//check if the return struct is empty, if yes then insert empty
|
|
|
if len(accounts) > 0 {
|
|
|
- return accounts[1:], nil
|
|
|
+ return accounts[1:], len(result), nil
|
|
|
} else {
|
|
|
- return []UserAccount{}, nil
|
|
|
+ return []UserAccount{}, 0, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -232,7 +233,7 @@ func (ldap *ldapHandler) convertGroup(ldapUser *ldap.Entry) UserAccount {
|
|
|
|
|
|
func (ldap *ldapHandler) TestConnection(w http.ResponseWriter, r *http.Request) {
|
|
|
//marshall it and return the connection status
|
|
|
- userList, err := ldap.getAllUser(10)
|
|
|
+ userList, totalLength, err := ldap.getAllUser(10)
|
|
|
if err != nil {
|
|
|
errMessage, err := json.Marshal(syncorizeUserReturnInterface{Error: err.Error()})
|
|
|
if err != nil {
|
|
@@ -242,7 +243,7 @@ func (ldap *ldapHandler) TestConnection(w http.ResponseWriter, r *http.Request)
|
|
|
common.SendJSONResponse(w, string(errMessage))
|
|
|
return
|
|
|
}
|
|
|
- returnJSON := syncorizeUserReturnInterface{Userinfo: userList, Length: len(userList), Error: ""}
|
|
|
+ returnJSON := syncorizeUserReturnInterface{Userinfo: userList, Length: len(userList), TotalLength: totalLength, Error: ""}
|
|
|
accountJSON, err := json.Marshal(returnJSON)
|
|
|
if err != nil {
|
|
|
errMessage, err := json.Marshal(syncorizeUserReturnInterface{Error: err.Error()})
|
|
@@ -312,7 +313,7 @@ func (ldap *ldapHandler) NightlySync() {
|
|
|
func (ldap *ldapHandler) SynchronizeUserFromLDAP() error {
|
|
|
//check if suer is admin before executing the command
|
|
|
//if user is admin then check if user will lost him/her's admin access
|
|
|
- ldapUsersList, err := ldap.getAllUser(-1)
|
|
|
+ ldapUsersList, _, err := ldap.getAllUser(-1)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|