From ba13a69f4acd020095a88eb26fb35f69bcb6a3fc Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Mon, 29 Oct 2012 21:52:02 +0100 Subject: [PATCH] Use http.StatusFound so the forms don't get redirected --- admin.go | 10 +++++----- trantor.go | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/admin.go b/admin.go index ae1bedf..e3959ce 100644 --- a/admin.go +++ b/admin.go @@ -72,9 +72,9 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) { } sess.Save(w, r) if isNew { - http.Redirect(w, r, "/new/", http.StatusTemporaryRedirect) + http.Redirect(w, r, "/new/", http.StatusFound) } else { - http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + http.Redirect(w, r, "/", http.StatusFound) } } @@ -144,9 +144,9 @@ func saveHandler(w http.ResponseWriter, r *http.Request) { sess.Notify("Book Modified!", "", "success") sess.Save(w, r) if db.BookActive(id) { - http.Redirect(w, r, "/book/"+idStr, http.StatusTemporaryRedirect) + http.Redirect(w, r, "/book/"+idStr, http.StatusFound) } else { - http.Redirect(w, r, "/new/", http.StatusTemporaryRedirect) + http.Redirect(w, r, "/new/", http.StatusFound) } } @@ -220,5 +220,5 @@ func storeHandler(w http.ResponseWriter, r *http.Request) { sess.Notify("Store books!", "The books '"+strings.Join(titles, ", ")+"' are stored for public download", "success") } sess.Save(w, r) - http.Redirect(w, r, "/new/", http.StatusTemporaryRedirect) + http.Redirect(w, r, "/new/", http.StatusFound) } diff --git a/trantor.go b/trantor.go index 96d73fb..714ccce 100644 --- a/trantor.go +++ b/trantor.go @@ -22,7 +22,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) { sess.LogOut() sess.Notify("Log out!", "Bye bye "+sess.User, "success") sess.Save(w, r) - http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + http.Redirect(w, r, "/", http.StatusFound) } func loginHandler(w http.ResponseWriter, r *http.Request) { @@ -31,14 +31,16 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { pass := r.FormValue("pass") sess := GetSession(r) if db.UserValid(user, pass) { + log.Println("User", user, "log in") sess.LogIn(user) sess.Notify("Successful login!", "Welcome "+user, "success") } else { + log.Println("User", user, "bad user or password") sess.Notify("Invalid login!", "user or password invalid", "error") } sess.Save(w, r) } - http.Redirect(w, r, r.Referer(), http.StatusTemporaryRedirect) + http.Redirect(w, r, r.Referer(), http.StatusFound) } type bookData struct {