guichet/pim_http.go

57 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-02-12 18:19:41 +00:00
package main
import (
"encoding/json"
"net/http"
)
2024-02-12 18:52:19 +00:00
type PimInspectView struct {
User *LoggedUser
Debug string
}
2024-02-12 18:19:41 +00:00
func handlePimInspect(w http.ResponseWriter, r *http.Request) {
user := RequireUserHtml(w, r)
if user == nil {
return
}
pim_ctl, err := NewPimBuilder(user).CheckCryptoRoot().CheckBucket().Build()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
pim_json, err := json.MarshalIndent(pim_ctl, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
2024-02-12 18:52:19 +00:00
view := PimInspectView {
User: user,
Debug: string(pim_json),
}
2024-02-12 18:19:41 +00:00
tKey := getTemplate("pim_inspect.html")
2024-02-12 18:52:19 +00:00
tKey.Execute(w, view)
2024-02-12 18:19:41 +00:00
}
func handlePimSetup(w http.ResponseWriter, r *http.Request) {
user := RequireUserHtml(w, r)
if user == nil {
return
}
_, err := NewPimBuilder(user).CheckCryptoRoot().CheckBucket().LdapUpdate().Build()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
user.Capabilities.CanUseEmail = true
http.Redirect(w, r, "/pim/inspect", http.StatusFound)
}