ictgj-voting/admin_endpoints.go

48 lines
1.1 KiB
Go
Raw Normal View History

2017-06-08 17:20:43 +00:00
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func initAdminRequest(w http.ResponseWriter, req *http.Request) *pageData {
p := InitPageData(w, req)
p.Stylesheets = append(p.Stylesheets, "/assets/css/admin.css")
p.Scripts = append(p.Scripts, "/assets/js/admin.js")
p.HideAdminMenu = false
return p
}
// Main admin handler, routes the request based on the category
func handleAdmin(w http.ResponseWriter, req *http.Request) {
page := initAdminRequest(w, req)
vars := mux.Vars(req)
if !page.LoggedIn {
if vars["category"] == "clients" &&
vars["id"] != "" &&
(vars["function"] == "add" || vars["function"] == "auth") {
// When authenticating a client, we have an all-in-one login/auth page
handleAdminClients(w, req, page)
} else {
page.SubTitle = "Admin Login"
page.show("admin-login.html", w)
}
} else {
adminCategory := vars["category"]
switch adminCategory {
case "users":
handleAdminUsers(w, req, page)
case "teams":
handleAdminTeams(w, req, page)
case "games":
handleAdminGames(w, req, page)
case "clients":
handleAdminClients(w, req, page)
default:
page.show("admin-main.html", w)
}
}
}