From c26dbb85981aee7c1f1fa1f37972126e5ac15e49 Mon Sep 17 00:00:00 2001 From: Emile Date: Fri, 23 Aug 2024 21:35:55 +0200 Subject: allow viewing battles without logging in --- src/battle.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/battle.go') 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 } -- cgit 1.4.1