2017-06-08 17:20:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-06-22 15:34:57 +00:00
|
|
|
"strconv"
|
2017-06-08 17:20:43 +00:00
|
|
|
|
|
|
|
"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)
|
2017-06-22 15:34:57 +00:00
|
|
|
case "votes":
|
|
|
|
handleAdminVotes(w, req, page)
|
|
|
|
case "mode":
|
|
|
|
handleAdminSetMode(w, req, page)
|
2017-06-08 17:20:43 +00:00
|
|
|
default:
|
2017-07-09 02:51:43 +00:00
|
|
|
page.TemplateData = getCondorcetResult()
|
2017-06-08 17:20:43 +00:00
|
|
|
page.show("admin-main.html", w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-22 15:34:57 +00:00
|
|
|
|
|
|
|
func handleAdminSetMode(w http.ResponseWriter, req *http.Request, page *pageData) {
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
newMode, err := strconv.Atoi(vars["id"])
|
|
|
|
if err != nil {
|
|
|
|
page.session.setFlashMessage("Invalid Mode: "+vars["id"], "error")
|
|
|
|
}
|
|
|
|
if dbSetPublicSiteMode(newMode) != nil {
|
|
|
|
page.session.setFlashMessage("Invalid Mode: "+vars["id"], "error")
|
|
|
|
}
|
|
|
|
redirect("/admin", w, req)
|
|
|
|
}
|