-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.go
84 lines (63 loc) · 1.54 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
package handlers
import (
"fmt"
"net/http"
"strconv"
DM "github.com/kycklingar/PBooru/DataManager"
)
func reportsHandler(w http.ResponseWriter, r *http.Request) {
u, _ := getUser(w, r)
if !u.Flag.Special() {
http.Error(w, "insufficent privileges. Want 'Special'", http.StatusBadRequest)
return
}
type page struct {
Reports []*DM.Report
}
var p page
var err error
p.Reports, err = DM.GetReports(DM.DB)
if internalError(w, err) {
return
}
renderTemplate(w, "reports", p)
}
func reportDeleteHandler(w http.ResponseWriter, r *http.Request) {
u, _ := getUser(w, r)
if !u.Flag.Special() {
http.Error(w, "insufficent privileges. Want 'Special'", http.StatusBadRequest)
return
}
rid, err := strconv.Atoi(r.FormValue("report-id"))
if badRequest(w, err) {
return
}
var rep = DM.NewReport()
rep.ID = rid
err = rep.Delete(DM.DB)
if internalError(w, err) {
return
}
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
}
func reportPostHandler(w http.ResponseWriter, r *http.Request) {
u, _ := getUser(w, r)
if u.ID <= 0 {
http.Error(w, "user not logged in", http.StatusBadRequest)
return
}
postID, err := strconv.Atoi(r.FormValue("post-id"))
if badRequest(w, err) {
return
}
var report = DM.NewReport()
report.Reason, err = strconv.Atoi(r.FormValue("reason"))
if badRequest(w, err) {
return
}
report.Description = r.FormValue("description")
report.Post.ID = postID
report.Reporter = u
internalError(w, report.Submit())
fmt.Fprint(w, "Thank you for the report, an admin will soon review the post")
}