diff --git a/admin.go b/admin.go index b4715e0..5051994 100644 --- a/admin.go +++ b/admin.go @@ -78,6 +78,7 @@ func isAdmin(r *http.Request) bool { func adminHandler(w http.ResponseWriter, r *http.Request) { if !isAdmin(r) { + http.Redirect(w, r, "/admin/login", http.StatusSeeOther) return } http.ServeFile(w, r, "templates/adminPanel.html") @@ -85,6 +86,7 @@ func adminHandler(w http.ResponseWriter, r *http.Request) { func adminTeamsHandler(w http.ResponseWriter, r *http.Request) { if !isAdmin(r) { + http.Redirect(w, r, "/admin/login", http.StatusSeeOther) return } rows, err := db.Query("SELECT name, difficulty_levels.level_name, last_cipher, penalty FROM teams JOIN difficulty_levels ON teams.difficulty_level = difficulty_levels.id ORDER BY teams.difficulty_level, teams.name") @@ -114,6 +116,7 @@ func adminTeamsHandler(w http.ResponseWriter, r *http.Request) { func AdminStartHandler(w http.ResponseWriter, r *http.Request) { if !isAdmin(r) { + http.Redirect(w, r, "/admin/login", http.StatusSeeOther) return } _, err := db.Exec("UPDATE teams SET last_cipher = 1, penalty = 0") @@ -131,7 +134,7 @@ func AdminStartHandler(w http.ResponseWriter, r *http.Request) { func AdminRouteHandler(w http.ResponseWriter, r *http.Request) { if !isAdmin(r) { - http.Error(w, "Unauthorized", http.StatusUnauthorized) + http.Redirect(w, r, "/admin/login", http.StatusSeeOther) return } // Fetch all difficulty levels