Implementing Activate User

This commit is contained in:
Chris Mann 2023-07-21 07:24:42 +02:00
parent acacc82903
commit 81c207ae28
3 changed files with 20 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"regexp"
"sort"
"strings"
"net/http"
"github.com/go-ldap/ldap/v3"
"github.com/gorilla/mux"
@ -51,6 +52,7 @@ func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
if login == nil {
return
}
searchRequest := ldap.NewSearchRequest(
config.InvitationBaseDN,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
@ -71,6 +73,22 @@ func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
Users: EntryList(sr.Entries),
}
templateAdminActivateUsers.Execute(w, data)
}
func handleAdminActivateUser(w http.ResponseWriter, r *http.Request) {
cn := mux.Vars(r)["cn"]
login := checkAdminLogin(w, r)
if login == nil {
return
}
modifyRequest := *ldap.NewModifyDNRequest("cn="+cn+","+config.InvitationBaseDN, "cn="+cn, true, config.UserBaseDN)
err := login.conn.ModifyDN(&modifyRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/admin/ldap/"+"cn="+cn+","+config.UserBaseDN), http.StatusFound)
}
func handleAdminUsers(w http.ResponseWriter, r *http.Request) {

View file

@ -62,6 +62,7 @@ func main() {
r.HandleFunc("/picture/{name}", handleDownloadPicture)
r.HandleFunc("/admin/activate", handleAdminActivateUsers)
r.HandleFunc("/admin/activate/{cn}", handleAdminActivateUser)
r.HandleFunc("/directory/search", handleDirectorySearch)
r.HandleFunc("/directory", handleDirectory)

View file

@ -11,7 +11,7 @@
{{range $user := $root.Users}}
<tr>
<td>
<a href="/admin/ldap/{{$user.DN}}">
<a href="/admin/activate/{{$user.CN}}">
{{$user.GetAttributeValue "cn"}}
</a>
</td>