|
@@ -177,10 +177,13 @@ func (ldap *ldapHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//@para limit: -1 means unlimited
|
|
|
-func (ldap *ldapHandler) getAllUser(limit int) []UserAccount {
|
|
|
+func (ldap *ldapHandler) getAllUser(limit int) ([]UserAccount, error) {
|
|
|
//read the user account from ldap, if limit is -1 then it will read all USERS
|
|
|
var accounts []UserAccount
|
|
|
- result, _ := ldap.ldapreader.GetAllUser()
|
|
|
+ result, err := ldap.ldapreader.GetAllUser()
|
|
|
+ if err != nil {
|
|
|
+ return []UserAccount{}, err
|
|
|
+ }
|
|
|
//loop through the result
|
|
|
for i, v := range result {
|
|
|
account := ldap.convertGroup(v)
|
|
@@ -191,9 +194,9 @@ func (ldap *ldapHandler) getAllUser(limit int) []UserAccount {
|
|
|
}
|
|
|
//check if the return struct is empty, if yes then insert empty
|
|
|
if len(accounts) > 0 {
|
|
|
- return accounts[1:]
|
|
|
+ return accounts[1:], nil
|
|
|
} else {
|
|
|
- return []UserAccount{}
|
|
|
+ return []UserAccount{}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -226,9 +229,18 @@ 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
|
|
|
- accountJSON, err := json.Marshal(ldap.getAllUser(10))
|
|
|
+ userList, err := ldap.getAllUser(10)
|
|
|
if err != nil {
|
|
|
- empty, err := json.Marshal(UserAccount{})
|
|
|
+ empty, err := json.Marshal(syncorizeUserReturnInterface{})
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, "Error while marshalling information")
|
|
|
+ }
|
|
|
+ common.SendJSONResponse(w, string(empty))
|
|
|
+ }
|
|
|
+ returnJSON := syncorizeUserReturnInterface{Userinfo: userList, Length: len(userList), Error: ""}
|
|
|
+ accountJSON, err := json.Marshal(returnJSON)
|
|
|
+ if err != nil {
|
|
|
+ empty, err := json.Marshal(syncorizeUserReturnInterface{})
|
|
|
if err != nil {
|
|
|
common.SendErrorResponse(w, "Error while marshalling information")
|
|
|
}
|
|
@@ -277,7 +289,10 @@ func (ldap *ldapHandler) SynchronizeUser(w http.ResponseWriter, r *http.Request)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ldapUsersList := ldap.getAllUser(-1)
|
|
|
+ ldapUsersList, err := ldap.getAllUser(-1)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ }
|
|
|
for _, ldapUser := range ldapUsersList {
|
|
|
//check if user exist in system
|
|
|
if ldap.ag.UserExists(ldapUser.Username) {
|