about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <git@emile.space>2024-08-23 21:35:55 +0200
committerEmile <git@emile.space>2024-08-23 21:35:55 +0200
commitc26dbb85981aee7c1f1fa1f37972126e5ac15e49 (patch)
treebd256ce78b3f684038bd3e805f980f0ba1f8b17e /src
parentf2f14353432c70f11973cdf865a002a267c3bd92 (diff)
allow viewing battles without logging in
Diffstat (limited to 'src')
-rw-r--r--src/battle.go13
-rw-r--r--src/main.go4
2 files changed, 11 insertions, 6 deletions
diff --git a/src/battle.go b/src/battle.go
index 7aa949a..ccac7e1 100644
--- a/src/battle.go
+++ b/src/battle.go
@@ -350,14 +350,19 @@ func battlesHandler(w http.ResponseWriter, r *http.Request) {
 
 		// sessions
 		session, _ := globalState.sessions.Get(r, "session")
-		username := session.Values["username"].(string)
+		username := session.Values["username"]
 
-		// get the user
-		user, err := UserGetUserFromUsername(username)
-		if err != nil {
+		if username == nil {
 			http.Redirect(w, r, "/login", http.StatusSeeOther)
 			return
 		} else {
+			// get the user
+			user, err := UserGetUserFromUsername(username.(string))
+			if err != nil {
+				http.Redirect(w, r, "/login", http.StatusSeeOther)
+				return
+			}
+
 			data["user"] = user
 		}
 
diff --git a/src/main.go b/src/main.go
index 65a3212..189468a 100644
--- a/src/main.go
+++ b/src/main.go
@@ -86,9 +86,9 @@ func main() {
 	auth_needed.HandleFunc("/user/{id}", userHandler)
 	auth_needed.HandleFunc("/user/{id}/profile", profileHandler)
 
-	auth_needed.HandleFunc("/battle", battlesHandler)
+	r.HandleFunc("/battle", battlesHandler)
 	auth_needed.HandleFunc("/battle/new", battleNewHandler)
-	auth_needed.HandleFunc("/battle/{id}", battleSingleHandler)
+	r.HandleFunc("/battle/{id}", battleSingleHandler)
 	auth_needed.HandleFunc("/battle/{id}/submit", battleSubmitHandler)
 
 	log.Printf("[i] HTTP Server running on %s:%d\n", host, port)