feat(webui): add user account status page
This commit is contained in:
parent
a22b2953e4
commit
2bf1731343
10 changed files with 230 additions and 12 deletions
66
pkg/webui/accountsId.go
Normal file
66
pkg/webui/accountsId.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package webui
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"git.adyxax.org/adyxax/tfstated/pkg/database"
|
||||
"git.adyxax.org/adyxax/tfstated/pkg/model"
|
||||
"go.n16f.net/uuid"
|
||||
)
|
||||
|
||||
type AccountsIdPage struct {
|
||||
Account *model.Account
|
||||
IsAdmin string
|
||||
Page *Page
|
||||
Username string
|
||||
StatePaths map[string]string
|
||||
UsernameDuplicate bool
|
||||
UsernameInvalid bool
|
||||
Versions []model.Version
|
||||
}
|
||||
|
||||
var accountsIdTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/accountsId.html"))
|
||||
|
||||
func handleAccountsIdGET(db *database.DB) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var accountId uuid.UUID
|
||||
if err := accountId.Parse(r.PathValue("id")); err != nil {
|
||||
errorResponse(w, r, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
account, err := db.LoadAccountById(accountId)
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
errorResponse(w, r, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
statePaths, err := db.LoadStatePaths()
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
versions, err := db.LoadVersionsByAccount(account)
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
isAdmin := ""
|
||||
if account.IsAdmin {
|
||||
isAdmin = "1"
|
||||
}
|
||||
render(w, accountsIdTemplates, http.StatusOK, AccountsIdPage{
|
||||
Account: account,
|
||||
IsAdmin: isAdmin,
|
||||
Page: makePage(r, &Page{
|
||||
Section: "accounts",
|
||||
Title: account.Username,
|
||||
}),
|
||||
StatePaths: statePaths,
|
||||
Versions: versions,
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue