diff --git a/ldap.go b/ldap.go index 1726be3..8c46a4e 100644 --- a/ldap.go +++ b/ldap.go @@ -168,6 +168,48 @@ func findLDAPAccountByEmail(email string) (string, error) { return entry.GetAttributeValue(Conf.Ldap.UserAttr), nil } +func findLDAPAccountForDisplay(uname string) (User, error) { + url := Conf.Ldap.Url + binddn := fmt.Sprintf("%v,%v", Conf.Ldap.AdminUser, Conf.Ldap.LdapDc) + basedn := fmt.Sprintf("%v,%v", Conf.Ldap.UserOu, Conf.Ldap.LdapDc) + l, err := ldap.DialURL(url) + if err != nil { + return User{}, err + } + defer l.Close() + err = l.Bind(binddn, Conf.Ldap.LdapPass) + if err != nil { + return User{}, err + } + result, err := l.Search(ldap.NewSearchRequest( + basedn, + ldap.ScopeWholeSubtree, + ldap.NeverDerefAliases, + 0, + 0, + false, + fmt.Sprintf("(&(objectClass=organizationalPerson)(%s=%s))", Conf.Ldap.UserAttr, uname), + []string{"cn", "sn", "givenName", "displayName", "mail", "employeeNumber"}, + nil, + )) + if err != nil { + return User{}, err + } + if len(result.Entries) != 1 { + err_text := fmt.Sprintf("Error finding user: Wanted 1 result, got %v\n", len(result.Entries)) + return User{}, errors.New(err_text) + } + entry := result.Entries[0] + u := User{ + Username: entry.GetAttributeValue("cn"), + FirstName: entry.GetAttributeValue("givenName"), + LastName: entry.GetAttributeValue("sn"), + DisplayName: entry.GetAttributeValue("displayName"), + Email: entry.GetAttributeValue("mail"), + ID: entry.GetAttributeValue("employeeNumber"), + } + return u, nil +} func findLDAPMaxID() (int, error) { url := Conf.Ldap.Url binddn := fmt.Sprintf("%v,%v", Conf.Ldap.AdminUser, Conf.Ldap.LdapDc) diff --git a/main.go b/main.go index 8728b9c..b44fa29 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func main() { router.HandleFunc("/login", login).Methods("POST") router.HandleFunc("/logout", logoutPage).Methods("GET") router.HandleFunc("/token", tokenPage).Methods("GET") + router.HandleFunc("/profile", profilePage).Methods("GET") router.HandleFunc("/passwordreset", resetPageFront).Methods("GET") router.HandleFunc("/passwordreset", resetLookup).Methods("POST") router.HandleFunc("/passwordresetform", resetPageBack).Methods("GET") diff --git a/templates/index.html b/templates/index.html index ace7ca6..a461339 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,6 +2,7 @@ {{ template "header" .}} {{if .LoggedIn }}
+ {{else}} diff --git a/templates/profile.html b/templates/profile.html new file mode 100644 index 0000000..fb2d9e0 --- /dev/null +++ b/templates/profile.html @@ -0,0 +1,26 @@ +{{ define "profile" }} +{{ template "header" .}} +Username: | {{ .User.Username }} | +
---|---|
Display Name: | {{ .User.DisplayName }} | +
First Name: | {{ .User.FirstName }} | +
Last Name: | {{ .User.LastName }} | +
Email Address: | {{ .User.Email }} | +
User ID: | {{ .User.ID }} | +