admin redirect to login
This commit is contained in:
5
admin.go
5
admin.go
@@ -78,6 +78,7 @@ func isAdmin(r *http.Request) bool {
|
|||||||
|
|
||||||
func adminHandler(w http.ResponseWriter, r *http.Request) {
|
func adminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAdmin(r) {
|
if !isAdmin(r) {
|
||||||
|
http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.ServeFile(w, r, "templates/adminPanel.html")
|
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) {
|
func adminTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAdmin(r) {
|
if !isAdmin(r) {
|
||||||
|
http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
|
||||||
return
|
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")
|
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) {
|
func AdminStartHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAdmin(r) {
|
if !isAdmin(r) {
|
||||||
|
http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err := db.Exec("UPDATE teams SET last_cipher = 1, penalty = 0")
|
_, 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) {
|
func AdminRouteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAdmin(r) {
|
if !isAdmin(r) {
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Fetch all difficulty levels
|
// Fetch all difficulty levels
|
||||||
|
|||||||
Reference in New Issue
Block a user