submit report
Cette révision appartient à :
Parent
e8c133fc69
révision
5f7adedab5
4 fichiers modifiés avec 38 ajouts et 7 suppressions
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,17 +92,17 @@
|
|||
<button type="button" class="close" data-dismiss="modal">×</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>
|
||||
|
||||
|
|
Référencer dans un nouveau ticket