40 lines
743 B
Go
40 lines
743 B
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"pool-stats/database"
|
|
)
|
|
|
|
type ControlPanelPageData struct {
|
|
PageDataBase
|
|
|
|
Message string
|
|
}
|
|
|
|
func (ws *WebServer) ControlPanelHandler(w http.ResponseWriter, r *http.Request) {
|
|
username := ws.getUser(r)
|
|
if username == "" {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
data := ControlPanelPageData{}
|
|
|
|
action := r.URL.Query().Get("action")
|
|
if action != "" {
|
|
data.Message = ws.executeAction(action)
|
|
}
|
|
|
|
ws.renderTemplate(w, r, "templates/cp.html", &data)
|
|
}
|
|
|
|
func (ws *WebServer) executeAction(action string) string {
|
|
switch action {
|
|
case "ClearDailyStats":
|
|
database.ClearDailyStats(ws.db)
|
|
return "Daily stats cleared successfully"
|
|
default:
|
|
return "Unknown action"
|
|
}
|
|
}
|