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" "regexp"
"sort" "sort"
"strings" "strings"
"net/http"
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -51,6 +52,7 @@ func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
if login == nil { if login == nil {
return return
} }
searchRequest := ldap.NewSearchRequest( searchRequest := ldap.NewSearchRequest(
config.InvitationBaseDN, config.InvitationBaseDN,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
@ -71,6 +73,22 @@ func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
Users: EntryList(sr.Entries), Users: EntryList(sr.Entries),
} }
templateAdminActivateUsers.Execute(w, data) 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) { func handleAdminUsers(w http.ResponseWriter, r *http.Request) {

View file

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

View file

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