fix captcha bug
This commit is contained in:
parent
0148aeb6af
commit
6274fff05b
@ -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 {
|
||||||
|
id, ok := s.Values["captcha_id"]
|
||||||
|
if ok {
|
||||||
|
redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, id)
|
||||||
|
http.Redirect(wr, r, redirect_url, 302)
|
||||||
|
} else {
|
||||||
captcha_id := captcha.New()
|
captcha_id := captcha.New()
|
||||||
s.Values["captcha_id"] = captcha_id
|
s.Values["captcha_id"] = captcha_id
|
||||||
s.Save(r, wr)
|
s.Save(r, wr)
|
||||||
redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, captcha_id)
|
redirect_url := fmt.Sprintf("%scaptcha/%s.png", self.prefix, captcha_id)
|
||||||
|
|
||||||
// redirect to the image
|
// redirect to the image
|
||||||
http.Redirect(wr, r, redirect_url, 302)
|
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")
|
||||||
|
Reference in New Issue
Block a user