From d24546237344a8c73acc9cc6605f7645477501d8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 30 Sep 2017 07:35:01 -0400 Subject: [PATCH] revert captcha, add stuff to js --- .../backends/srndv2/src/srnd/frontend_http.go | 19 ++++++----------- contrib/static/overchan.js | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/frontend_http.go b/contrib/backends/srndv2/src/srnd/frontend_http.go index 1bf8e71..1003df9 100644 --- a/contrib/backends/srndv2/src/srnd/frontend_http.go +++ b/contrib/backends/srndv2/src/srnd/frontend_http.go @@ -993,19 +993,12 @@ func (self httpFrontend) handle_poster(wr http.ResponseWriter, r *http.Request) func (self *httpFrontend) serve_captcha(wr http.ResponseWriter, r *http.Request) { s, err := self.store.Get(r, self.name) if err == nil { - id, ok := s.Values["captcha_id"] - if ok { - redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, id) - s.Save(r, wr) - http.Redirect(wr, r, redirect_url, 302) - } else { - captcha_id := captcha.New() - s.Values["captcha_id"] = captcha_id - s.Save(r, wr) - redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, captcha_id) - // redirect to the image - http.Redirect(wr, r, redirect_url, 302) - } + captcha_id := captcha.New() + s.Values["captcha_id"] = captcha_id + s.Save(r, wr) + redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, captcha_id) + // redirect to the image + http.Redirect(wr, r, redirect_url, 302) } else { // handle session error // TODO: clear cookies? diff --git a/contrib/static/overchan.js b/contrib/static/overchan.js index e247ca3..dcf24e5 100644 --- a/contrib/static/overchan.js +++ b/contrib/static/overchan.js @@ -31,7 +31,28 @@ function get_storage() { return st; } +function setSrcQuery(e, q) { + var src = e.src; + var p = src.indexOf('?'); + if (p >= 0) { + src = src.substr(0, p); + } + e.src = src + "?" + q +} +function reload(el) { + setSrcQuery(el, "reload=" + (new Date()).getTime()); + return false; +} +// captcha reload +onready(function(){ + var e = document.getElementById("captcha_img"); + if (e) { + e.onclick = function() { + reload(e); + }; + } +}); // rewrite all images to add inline expand onready(function() {