validate captcha before processing
Cette révision appartient à :
Parent
99244542b5
révision
ffa5163a41
2 fichiers modifiés avec 6 ajouts et 9 suppressions
|
@ -86,6 +86,12 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
f.Magnet = r.FormValue(UploadFormMagnet)
|
||||
f.Captcha = captcha.Extract(r)
|
||||
|
||||
if !captcha.Authenticate(f.Captcha) {
|
||||
// TODO: Prettier passing of mistyoed captcha errors
|
||||
return errors.New(captcha.ErrInvalidCaptcha.Error())
|
||||
}
|
||||
|
||||
|
||||
// trim whitespaces
|
||||
f.Name = util.TrimWhitespaces(f.Name)
|
||||
f.Description = p.Sanitize(util.TrimWhitespaces(f.Description))
|
||||
|
|
|
@ -3,7 +3,6 @@ package router
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -21,14 +20,6 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
// validation is done in ExtractInfo()
|
||||
err = uploadForm.ExtractInfo(r)
|
||||
if err == nil {
|
||||
if !captcha.Authenticate(uploadForm.Captcha) {
|
||||
// TODO: Prettier passing of mistyoed captcha errors
|
||||
http.Error(w, captcha.ErrInvalidCaptcha.Error(), 403)
|
||||
if len(uploadForm.Filepath) > 0 {
|
||||
os.Remove(uploadForm.Filepath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//add to db and redirect depending on result
|
||||
torrent := model.Torrents{
|
||||
|
|
Référencer dans un nouveau ticket