Use http.StatusFound so the forms don't get redirected

This commit is contained in:
Las Zenow 2012-10-29 21:52:02 +01:00
parent 857dc5f57c
commit ba13a69f4a
2 changed files with 9 additions and 7 deletions

View file

@ -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)
}

View file

@ -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 {