AY's Macbook Pro 3 éve
szülő
commit
ccd754a2fe
1 módosított fájl, 6 hozzáadás és 12 törlés
  1. 6 12
      mod/auth/ldap/ldap.go

+ 6 - 12
mod/auth/ldap/ldap.go

@@ -44,11 +44,6 @@ type UserAccount struct {
 	EquivGroup []string `json:"equiv_group"`
 }
 
-/*
-TODO: not sure why auto redirect will keep enable
-TODO: stop user to syncorize if the current user will lost admin access
-*/
-
 //NewLdapHandler xxx
 func NewLdapHandler(authAgent *auth.AuthAgent, register *reg.RegisterHandler, coreDb *db.Database, permissionHandler *permission.PermissionHandler, userHandler *user.UserHandler, iconSystem string) *ldapHandler {
 	//ldap handler init
@@ -117,16 +112,12 @@ func (ldap *ldapHandler) ReadConfig(w http.ResponseWriter, r *http.Request) {
 }
 
 func (ldap *ldapHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
+	//receive the parameter
 	enabled, err := common.Mv(r, "enabled", true)
 	if err != nil {
 		common.SendErrorResponse(w, "enabled field can't be empty")
 		return
 	}
-	autoredirect, err := common.Mv(r, "autoredirect", true)
-	if err != nil {
-		common.SendErrorResponse(w, "enabled field can't be empty")
-		return
-	}
 
 	//allow empty fields if enabled is false
 	showError := true
@@ -164,8 +155,8 @@ func (ldap *ldapHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
+	//write the data back to db
 	ldap.coredb.Write("ldap", "enabled", enabled)
-	ldap.coredb.Write("ldap", "autoredirect", autoredirect)
 	ldap.coredb.Write("ldap", "BindUsername", BindUsername)
 	ldap.coredb.Write("ldap", "BindPassword", BindPassword)
 	ldap.coredb.Write("ldap", "FQDN", FQDN)
@@ -174,11 +165,13 @@ func (ldap *ldapHandler) WriteConfig(w http.ResponseWriter, r *http.Request) {
 	//update the new authencation infromation
 	ldap.ldapreader = ldapreader.NewLDAPReader(BindUsername, BindPassword, FQDN, BaseDN)
 
+	//return ok
 	common.SendOK(w)
 }
 
 //@para limit: -1 means unlimited
 func (ldap *ldapHandler) getAllUser(limit int) []UserAccount {
+	//read the user account from ldap, if limit is -1 then it will read all USERS
 	var accounts []UserAccount
 	result, _ := ldap.ldapreader.GetAllUser()
 	//loop through the result
@@ -189,6 +182,7 @@ func (ldap *ldapHandler) getAllUser(limit int) []UserAccount {
 			break
 		}
 	}
+	//check if the return struct is empty, if yes then insert empty
 	if len(accounts) > 0 {
 		return accounts[1:]
 	} else {
@@ -224,7 +218,7 @@ func (ldap *ldapHandler) convertGroup(ldapUser *ldap.Entry) UserAccount {
 }
 
 func (ldap *ldapHandler) TestConnection(w http.ResponseWriter, r *http.Request) {
-	//marshall it and return
+	//marshall it and return the connection status
 	accountJSON, err := json.Marshal(ldap.getAllUser(10))
 	if err != nil {
 		empty, err := json.Marshal(UserAccount{})