feat(webui): add user accounts list, admin middleware and admin restricted menu entries
This commit is contained in:
parent
fb98b4fffe
commit
e23a146490
9 changed files with 143 additions and 2 deletions
31
pkg/webui/accounts.go
Normal file
31
pkg/webui/accounts.go
Normal 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,
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue