Add users button to home

This commit is contained in:
Melon 2024-02-12 20:58:49 +00:00
parent c6d64e5d81
commit ef55d260de
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"github.com/1f349/lavender/database"
"github.com/1f349/lavender/pages" "github.com/1f349/lavender/pages"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
@ -16,6 +17,13 @@ func (h *HttpServer) Home(rw http.ResponseWriter, _ *http.Request, _ httprouter.
return return
} }
var isAdmin bool
h.DbTx(rw, func(tx *database.Tx) (err error) {
roles, err := tx.GetUserRoles(auth.Data.ID)
isAdmin = HasRole(roles, "lavender:admin")
return err
})
lNonce := uuid.NewString() lNonce := uuid.NewString()
auth.Session.Set("action-nonce", lNonce) auth.Session.Set("action-nonce", lNonce)
if auth.Session.Save() != nil { if auth.Session.Save() != nil {
@ -29,5 +37,6 @@ func (h *HttpServer) Home(rw http.ResponseWriter, _ *http.Request, _ httprouter.
"Subject": auth.Data.ID, "Subject": auth.Data.ID,
"DisplayName": auth.Data.DisplayName, "DisplayName": auth.Data.DisplayName,
"Nonce": lNonce, "Nonce": lNonce,
"IsAdmin": isAdmin,
}) })
} }