1
0

Show Go back on error page, need to pass a referer URL for it.

This commit is contained in:
Alexander Andreev 2023-08-12 23:51:26 +04:00
parent 87453e160d
commit 6fe6c856cd
Signed by: Arav
GPG Key ID: D22A817D95815393
4 changed files with 14 additions and 11 deletions

View File

@ -74,8 +74,8 @@ func main() {
r := httpr.New()
r.NotFoundHandler = func(w http.ResponseWriter, _ *http.Request) {
web.ErrorXXX("/ Not Found", "", "", http.StatusNotFound, w)
r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) {
web.ErrorXXX("/ Not Found", "", "", r.Referer(), http.StatusNotFound, w)
}
r.ServeStatic("/assets/*filepath", web.Assets())

View File

@ -29,7 +29,8 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) {
Error(w, http.StatusForbidden, "Wrong answer given.", "Here's your message:"+r.FormValue("message"))
Error(w, http.StatusForbidden, "Wrong answer given.",
"Here's your message:"+r.FormValue("message"), r.Referer())
return
}
@ -42,13 +43,15 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
entry, err = justguestbook.NewEntry(r.FormValue("name"), message,
r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "Here's your message:"+r.FormValue("message"))
Error(w, http.StatusInternalServerError, err.Error(),
"Here's your message:"+r.FormValue("message"), r.Referer())
return
}
}
if err = h.db.NewEntry(entry); err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "Here's your message:"+r.FormValue("message"))
Error(w, http.StatusInternalServerError, err.Error(),
"Here's your message:"+r.FormValue("message"), r.Referer())
return
}

View File

@ -51,7 +51,7 @@ func (h *MindflowApiHandlers) NewPost(w http.ResponseWriter, r *http.Request) {
if err = h.db.NewPost(post); err != nil {
msg := strings.Join([]string{"Title:", r.FormValue("title"), "| Body:", r.FormValue("body")}, " ")
Error(w, http.StatusInternalServerError, err.Error(), msg)
Error(w, http.StatusInternalServerError, err.Error(), msg, r.Referer())
return
}

View File

@ -70,13 +70,13 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) {
posts, err := h.mindflowDB.Posts()
if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "failed to load posts")
Error(w, http.StatusInternalServerError, err.Error(), "failed to load posts", r.Referer())
return
}
categories, err := h.mindflowDB.Categories()
if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "failed to load categories")
Error(w, http.StatusInternalServerError, err.Error(), "failed to load categories", r.Referer())
return
}
@ -153,7 +153,7 @@ func (h *Handlers) GuestbookAdmin(w http.ResponseWriter, r *http.Request) {
entriesCount, _ := h.guestbookDB.Count()
entries, err := h.guestbookDB.Entries(1, entriesCount)
if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "cannot load gb")
Error(w, http.StatusInternalServerError, err.Error(), "cannot load gb", r.Referer())
return
}
for _, entry := range entries {
@ -187,8 +187,8 @@ func SitemapXml(w http.ResponseWriter, r *http.Request) {
w.Write(data)
}
func Error(w http.ResponseWriter, code int, reason, message string) {
web.ErrorXXX("/ "+http.StatusText(code), reason, message, code, w)
func Error(w http.ResponseWriter, code int, reason, message, referer string) {
web.ErrorXXX("/ "+http.StatusText(code), reason, message, referer, code, w)
}
func cleanupNewlines(text string) (out string) {