feat(webui): add user accounts list, admin middleware and admin restricted menu entries

This commit is contained in:
Julien Dessaux 2025-02-26 00:07:35 +01:00
parent fb98b4fffe
commit e23a146490
Signed by: adyxax
GPG key ID: F92E51B86E07177E
9 changed files with 143 additions and 2 deletions

31
pkg/webui/accounts.go Normal file
View file

@ -0,0 +1,31 @@
package webui
import (
"html/template"
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/database"
"git.adyxax.org/adyxax/tfstated/pkg/model"
)
type AccountsPage struct {
ActiveTab int
Page *Page
Accounts []model.Account
}
var accountsTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/accounts.html"))
func handleAccountsGET(db *database.DB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accounts, err := db.LoadAccounts()
if err != nil {
errorResponse(w, http.StatusInternalServerError, err)
return
}
render(w, accountsTemplates, http.StatusOK, AccountsPage{
Page: makePage(r, &Page{Title: "User Accounts", Section: "accounts"}),
Accounts: accounts,
})
})
}