This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
/
report.go
92 lines (81 loc) · 1.7 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package server
import (
"meguca/auth"
"meguca/common"
"meguca/db"
"meguca/templates"
"net/http"
"strconv"
)
// Report a post for rule violations
func report(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, jsonLimit)
err := r.ParseMultipartForm(0)
if err != nil {
text400(w, err)
return
}
f := r.Form
if !auth.AuthenticateCaptcha(auth.Captcha{
CaptchaID: f.Get("captchaID"),
Solution: f.Get("captcha"),
}) {
text403(w, errInvalidCaptcha)
return
}
target, err := strconv.ParseUint(f.Get("target"), 10, 64)
if err != nil {
text400(w, err)
return
}
board, err := db.GetPostBoard(target)
if err != nil {
text400(w, err)
return
}
if !auth.IsNonMetaBoard(board) {
text400(w, errInvalidBoardName)
return
}
if !assertNotBanned(w, r, board) {
return
}
ip, err := auth.GetIP(r)
if err != nil {
text400(w, err)
return
}
reason := f.Get("reason")
if len(reason) > common.MaxLenReason {
text400(w, errReasonTooLong)
return
}
err = db.Report(target, board, reason, ip, f.Get("illegal") == "on")
if err != nil {
text500(w, r, err)
return
}
}
// Render post reporting form
func reportForm(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseUint(extractParam(r, "id"), 10, 64)
if err != nil {
text400(w, err)
return
}
serveHTML(w, r, "", []byte(templates.ReportForm(id)), nil)
}
// Render a list of reports for the board
func reportList(w http.ResponseWriter, r *http.Request) {
board := extractParam(r, "board")
if !auth.IsNonMetaBoard(board) {
text404(w)
return
}
rep, err := db.GetReports(board)
if err != nil {
text500(w, r, err)
return
}
serveHTML(w, r, "", []byte(templates.ReportList(rep)), nil)
}