From 7a4b91304061777e7b3365b505d1e74878043d35 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 30 Jun 2026 02:17:22 -0400 Subject: feat: web gui mapping and obj/item/mob placement improvements --- internal/admin/server.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'internal/admin/server.go') diff --git a/internal/admin/server.go b/internal/admin/server.go index 418a693..8facc4a 100644 --- a/internal/admin/server.go +++ b/internal/admin/server.go @@ -212,12 +212,11 @@ func (s *AdminServer) checkAuth(r *http.Request) bool { } func (s *AdminServer) isAdminAccount(name string) bool { - for _, a := range s.cfg.AdminHTTPS.AdminAccounts { - if strings.EqualFold(a, name) { - return true - } + acc, err := s.accountStore.LoadAccount(name) + if err != nil { + return false } - return false + return acc.Admin } func (s *AdminServer) setAuthCookie(w http.ResponseWriter, account string) { @@ -249,17 +248,17 @@ func (s *AdminServer) handleLogin(w http.ResponseWriter, r *http.Request) { account := strings.TrimSpace(r.FormValue("account")) password := r.FormValue("password") - if !s.isAdminAccount(account) { - s.renderPage(w, r, "login.html", map[string]any{"Error": "Account is not authorized as admin."}) - return - } - acc, err := s.accountStore.LoadAccount(account) if err != nil || !player.CheckPassword(password, acc.PasswordHash) { s.renderPage(w, r, "login.html", map[string]any{"Error": "Invalid account name or password."}) return } + if !acc.Admin { + s.renderPage(w, r, "login.html", map[string]any{"Error": "Account is not authorized as admin."}) + return + } + s.setAuthCookie(w, account) http.Redirect(w, r, "/", http.StatusFound) } @@ -355,6 +354,12 @@ func writeJSON(w http.ResponseWriter, data any) { } } +func writeJSONError(w http.ResponseWriter, msg string, code int) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) + json.NewEncoder(w).Encode(map[string]any{"error": msg}) +} + func readJSON(r *http.Request, v any) error { body, err := io.ReadAll(r.Body) if err != nil { -- cgit v1.2.3