Refactoring into admin.go activate

This commit is contained in:
Chris Mann 2023-07-21 06:51:56 +02:00
parent 0613a7ed6d
commit e9adb8d0c0
3 changed files with 55 additions and 0 deletions

View file

@ -45,6 +45,34 @@ type AdminUsersTplData struct {
Users EntryList Users EntryList
} }
func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
templateAdminActivateUsers := getTemplate("admin_activate.html")
login := checkAdminLogin(w, r)
if login == nil {
return
}
searchRequest := ldap.NewSearchRequest(
config.InvitationBaseDN,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=organizationalPerson))"),
[]string{config.UserNameAttr, "dn", "displayName", "givenName", "sn", "mail", "uid", "cn"},
nil)
sr, err := login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := &AdminUsersTplData{
Login: login,
UserNameAttr: config.UserNameAttr,
UserBaseDN: config.UserBaseDN,
Users: EntryList(sr.Entries),
}
templateAdminActivateUsers.Execute(w, data)
}
func handleAdminUsers(w http.ResponseWriter, r *http.Request) { func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
templateAdminUsers := getTemplate("admin_users.html") templateAdminUsers := getTemplate("admin_users.html")

View file

@ -61,6 +61,8 @@ func main() {
r.HandleFunc("/passwd", handlePasswd) r.HandleFunc("/passwd", handlePasswd)
r.HandleFunc("/picture/{name}", handleDownloadPicture) r.HandleFunc("/picture/{name}", handleDownloadPicture)
r.HandleFunc("/admin/activate", handleAdminActivateUsers)
r.HandleFunc("/directory/search", handleDirectorySearch) r.HandleFunc("/directory/search", handleDirectorySearch)
r.HandleFunc("/directory", handleDirectory) r.HandleFunc("/directory", handleDirectory)

View file

@ -0,0 +1,25 @@
{{define "title"}}Activer des utilisateurs |{{end}}
<table class="table mt-4">
<thead>
<th scope="col">Identifiant</th>
<th scope="col">Nom complet</th>
</thead>
<tbody>
{{with $root := .}}
{{range $user := $root.Users}}
<tr>
<td>
<a href="/admin/ldap/{{$group.DN}}">
{{$user.GetAttributeValue $user.UserNameAttr}}
</a>
</td>
<td>{{$user.GetAttributeValue "mail"}}</td>
<td>{{$user.GetAttributeValue "displayname"}}</td>
<td>{{$user.GetAttributeValue "sn"}}</td>
<td>{{$user.GetAttributeValue "description"}}</td>
</tr>
{{end}}
{{end}}
</tbody>
</table>