Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

submit report

Cette révision appartient à :
Your Name 2017-05-10 08:17:21 +00:00
Parent e8c133fc69
révision 5f7adedab5
4 fichiers modifiés avec 38 ajouts et 7 suppressions

Voir le fichier

@ -4,7 +4,7 @@ import (
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/util/log"
"github.com/jinzhu/gorm"
"github.com/azhao12345/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)

Voir le fichier

@ -93,6 +93,8 @@ func init() {
Router.Handle("/mod/torrent/delete", gzipTorrentDeleteModPanel).Name("mod_tdelete")
Router.Handle("/mod/comment/delete", gzipCommentDeleteModPanel).Name("mod_cdelete")
//reporting a torrent
Router.HandleFunc("/report/{id}", ReportTorrentHandler).Methods("POST").Name("post_comment")
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)

Voir le fichier

@ -63,3 +63,32 @@ err = db.ORM.Create(&comment).Error
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
userCaptcha := captcha.Extract(r)
if !captcha.Authenticate(userCaptcha) {
http.Error(w, "bad captcha", 403)
}
currentUser := GetUser(r)
idNum, err := strconv.Atoi(id)
userID := currentUser.ID
report := model.TorrentReport{Description: r.FormValue("report_type"), TorrentID: uint(idNum), UserID: userID}
err = db.ORM.Create(&report).Error
if err != nil {
util.SendError(w, err, 500)
return
}
url, err := Router.Get("view_torrent").URL("id", id)
if err == nil {
http.Redirect(w, r, url.String(), 302)
} else {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

Voir le fichier

@ -92,17 +92,17 @@
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Report Torrent #{{.ID}}</h4>
</div>
{{end}}
<div class="modal-body">
<b>Report type:</b>
<form action="">
<input type="radio" name="report" value="illegal"> Illegal content <br/>
<input type="radio" name="report" value="spam"> Spam / garbage
</form> <br />
<form method="post" action="/report/{{.ID}}">
<input type="radio" name="report_type" value="illegal"> Illegal content <br/>
<input type="radio" name="report_type" value="spam"> Spam / garbage
{{end}}
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<button type="submit" class="btn btn-default">Report!</button>
</form> <br />
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">Report!</button>
</div>
</div>