show groups in profile

This commit is contained in:
stryan 2021-03-31 16:12:35 -04:00
parent 8e8e67666c
commit 2624034fd7
3 changed files with 34 additions and 14 deletions

13
ldap.go
View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"github.com/go-ldap/ldap"
)
@ -251,7 +252,7 @@ func findLDAPAccountForDisplay(uname string) (User, error) {
0,
false,
fmt.Sprintf("(&(objectClass=organizationalPerson)(%s=%s))", Conf.Ldap.UserAttr, uname),
[]string{"cn", "sn", "givenName", "displayName", "mail", "employeeNumber"},
[]string{"cn", "sn", "givenName", "displayName", "mail", "employeeNumber", "memberOf"},
nil,
))
if err != nil {
@ -262,6 +263,14 @@ func findLDAPAccountForDisplay(uname string) (User, error) {
return User{}, errors.New(err_text)
}
entry := result.Entries[0]
groups := entry.GetAttributeValues("memberOf")
fg := make([]string, 0)
for _, group := range groups {
group_s := strings.Split(group, ",")
group_cn := group_s[0]
fg = append(fg, strings.Trim(group_cn, "cn="))
}
u := User{
Username: entry.GetAttributeValue("cn"),
FirstName: entry.GetAttributeValue("givenName"),
@ -269,6 +278,8 @@ func findLDAPAccountForDisplay(uname string) (User, error) {
DisplayName: entry.GetAttributeValue("displayName"),
Email: entry.GetAttributeValue("mail"),
ID: entry.GetAttributeValue("employeeNumber"),
Groups: groups,
FriendlyGroups: fg,
}
return u, nil
}

View File

@ -1,6 +1,6 @@
{{ define "profile" }}
{{ template "header" .}}
<h1> Profile </h1>
<h1>User Profile </h1>
<table>
<tr>
<th>Username: </th><td>{{ .User.Username }}</td>
@ -20,6 +20,13 @@
<tr>
<th>User ID: </th><td>{{ .User.ID }}</td>
</tr>
</table>
<h1>User Groups </h1>
<table>
{{range .User.FriendlyGroups}}
<tr><th>Group: </th><td>{{.}}</td></tr>
{{end}}
</table>
<p><a href="/profile/edit">Edit Profile</a></p>
{{ template "footer" .}}

View File

@ -7,6 +7,8 @@ type User struct {
DisplayName string
Email string
ID string
Groups []string
FriendlyGroups []string
}
//TODO Start using User as a proper model