Add_Directory_and_ProfilePicture #9

Merged
lx merged 13 commits from Add_Directory into main 2021-08-16 14:44:53 +00:00
6 changed files with 32 additions and 5 deletions
Showing only changes of commit 815e9bfe2a - Show all commits

View file

@ -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

View file

@ -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)

View file

@ -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 {

View file

@ -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 = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].identifiant}</a>`
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)

View file

@ -22,6 +22,7 @@
<th scope="col">Identifiant</th>
<th scope="col">Nom complet</th>
<th scope="col">Email</th>
<th scope="col">Description</th>
</thead>
<tbody id="users">

View file

@ -37,6 +37,18 @@
<label for="surname">Nom de famille:</label>
<input type="text" id="surname" name="surname" class="form-control" value="{{ .Surname }}" />
</div>
<div class="form-group">
<label for="description">Description (180 caractères maximum)</label>
<textarea id="description" name="description" class="form-control" maxlength="180">{{ .Description }}</textarea>
</div>
<div class="form-group form-check">
{{if .Visibility}}
<input class="form-check-input" name="visibility" type="checkbox" id="visibility" checked>
{{else}}
<input class="form-check-input" name="visibility" type="checkbox" id="visibility">
{{end}}
<label class="form-check-label" for="visibility">Apparaît sur l'annuaire</label>
</div>
<button type="submit" class="btn btn-primary">Enregistrer les modifications</button>
</form>
{{end}}