diff --git a/directory.go b/directory.go index 6a7ade2..6c1ab29 100644 --- a/directory.go +++ b/directory.go @@ -25,6 +25,7 @@ type SearchResult struct { Identifiant string `json:"identifiant"` Name string `json:"name"` Email string `json:"email"` + Description string `json:"description"` DN string `json:"dn"` } @@ -47,12 +48,12 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { return } - //Search value with ldap and filter + //Search values with ldap and filter searchRequest := ldap.NewSearchRequest( config.UserBaseDN, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, - "(&(objectclass=organizationalPerson)(visibility=all))", - []string{config.UserNameAttr, "displayname", "mail"}, + "(&(objectclass=organizationalPerson)(visibility=on))", + []string{config.UserNameAttr, "displayname", "mail", "description"}, nil) sr, err := login.conn.Search(searchRequest) @@ -71,6 +72,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { Identifiant: values.GetAttributeValue("cn"), Name: values.GetAttributeValue("displayname"), Email: values.GetAttributeValue("email"), + Description: values.GetAttributeValue("description"), DN: values.DN, }), } @@ -78,7 +80,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { } - //Convert interface to uint32 with Type Assertions and not a simple convert + //Convert interface to uint32 with Type Assertions and not a simple convert for messageID if val_Raw, ok_raw := session.Values["MessageID"]; ok_raw { if val, ok := val_Raw.(uint32); ok { val += 1 diff --git a/main.go b/main.go index da75ce0..98a9cdd 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { login_info.DN, ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, requestKind, - []string{"dn", "displayname", "givenname", "sn", "mail", "memberof"}, + []string{"dn", "displayname", "givenname", "sn", "mail", "memberof", "visibility", "description"}, nil) sr, err := l.Search(searchRequest) diff --git a/profile.go b/profile.go index e7a54bd..ba317fe 100644 --- a/profile.go +++ b/profile.go @@ -16,6 +16,8 @@ type ProfileTplData struct { DisplayName string GivenName string Surname string + Visibility string + Description string } func handleProfile(w http.ResponseWriter, r *http.Request) { @@ -36,6 +38,8 @@ func handleProfile(w http.ResponseWriter, r *http.Request) { data.DisplayName = login.UserEntry.GetAttributeValue("displayname") data.GivenName = login.UserEntry.GetAttributeValue("givenname") data.Surname = login.UserEntry.GetAttributeValue("sn") + data.Visibility = login.UserEntry.GetAttributeValue("visibility") + data.Description = login.UserEntry.GetAttributeValue("description") if r.Method == "POST" { r.ParseForm() @@ -43,11 +47,15 @@ func handleProfile(w http.ResponseWriter, r *http.Request) { data.DisplayName = strings.TrimSpace(strings.Join(r.Form["display_name"], "")) data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], "")) data.Surname = strings.TrimSpace(strings.Join(r.Form["surname"], "")) + data.Description = strings.Trim(strings.Join(r.Form["description"], ""), "") + data.Visibility = strings.TrimSpace(strings.Join(r.Form["visibility"], "")) modify_request := ldap.NewModifyRequest(login.Info.DN, nil) modify_request.Replace("displayname", []string{data.DisplayName}) modify_request.Replace("givenname", []string{data.GivenName}) modify_request.Replace("sn", []string{data.Surname}) + modify_request.Replace("description", []string{data.Description}) + modify_request.Replace("visibility", []string{data.Visibility}) err := login.conn.Modify(modify_request) if err != nil { diff --git a/static/javascript/search.js b/static/javascript/search.js index 7675c0e..9e078be 100644 --- a/static/javascript/search.js +++ b/static/javascript/search.js @@ -23,9 +23,13 @@ function searchDirectory() { var identifiant = row.insertCell(0); var name = row.insertCell(1); var email = row.insertCell(2); + var description = row.insertCell(3); + description.setAttribute("style", "word-break: break-all;"); + identifiant.innerHTML = `${jsonResponse.search[i].identifiant}` name.innerHTML = jsonResponse.search[i].name email.innerHTML = jsonResponse.search[i].email + description.innerHTML = `${jsonResponse.search[i].description}` } old_table.parentNode.replaceChild(table, old_table) diff --git a/templates/directory.html b/templates/directory.html index bdc587f..e91354d 100644 --- a/templates/directory.html +++ b/templates/directory.html @@ -22,6 +22,7 @@ Identifiant Nom complet Email + Description diff --git a/templates/profile.html b/templates/profile.html index bfd79cd..5445d6d 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -37,6 +37,18 @@ +
+ + +
+
+ {{if .Visibility}} + + {{else}} + + {{end}} + +
{{end}}