Archived
1
0

fix captcha bug

This commit is contained in:
Jeff Becker 2017-09-30 07:28:55 -04:00
parent 0148aeb6af
commit 6274fff05b
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -990,16 +990,21 @@ func (self httpFrontend) handle_poster(wr http.ResponseWriter, r *http.Request)
} }
} }
func (self *httpFrontend) new_captcha(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) s, err := self.store.Get(r, self.name)
if err == nil { if err == nil {
captcha_id := captcha.New() id, ok := s.Values["captcha_id"]
s.Values["captcha_id"] = captcha_id if ok {
s.Save(r, wr) redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, id)
redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, captcha_id) http.Redirect(wr, r, redirect_url, 302)
} else {
// redirect to the image captcha_id := captcha.New()
http.Redirect(wr, r, redirect_url, 302) 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 { } else {
// handle session error // handle session error
// TODO: clear cookies? // TODO: clear cookies?
@ -1466,7 +1471,7 @@ func (self *httpFrontend) Mainloop() {
m.PathPrefix("/static/").Handler(http.FileServer(http.Dir(self.static_dir))) m.PathPrefix("/static/").Handler(http.FileServer(http.Dir(self.static_dir)))
m.PathPrefix("/post/").HandlerFunc(self.handle_poster).Methods("POST") m.PathPrefix("/post/").HandlerFunc(self.handle_poster).Methods("POST")
m.Path("/captcha/new").HandlerFunc(self.new_captcha_json).Methods("GET") m.Path("/captcha/new").HandlerFunc(self.new_captcha_json).Methods("GET")
m.Path("/captcha/img").HandlerFunc(self.new_captcha).Methods("GET") m.Path("/captcha/img").HandlerFunc(self.serve_captcha).Methods("GET")
m.Path("/captcha/{f}").Handler(captcha.Server(350, 175)).Methods("GET") m.Path("/captcha/{f}").Handler(captcha.Server(350, 175)).Methods("GET")
m.Path("/new/").HandlerFunc(self.handle_newboard).Methods("GET") m.Path("/new/").HandlerFunc(self.handle_newboard).Methods("GET")
m.Path("/api/{meth}").HandlerFunc(self.handle_api).Methods("POST", "GET") m.Path("/api/{meth}").HandlerFunc(self.handle_api).Methods("POST", "GET")