-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreport.go
163 lines (142 loc) · 3.97 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"database/sql"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
func reportForm(c *gin.Context) {
if getContext(c).User.ID == 0 {
resp403(c)
return
}
var (
userID int
username string
privileges uint64
)
ctx := getContext(c)
u := c.Param("user")
if _, err := strconv.Atoi(u); err != nil {
err := db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1", u).Scan(&userID, &username, &privileges)
if err != nil && err != sql.ErrNoRows {
c.Error(err)
}
} else {
err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
switch {
case err == nil:
case err == sql.ErrNoRows:
err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
if err != nil && err != sql.ErrNoRows {
c.Error(err)
}
default:
c.Error(err)
}
}
data := new(profileData)
data.UserID = userID
if data.UserID == getContext(c).User.ID {
addMessage(c, errorMessage{T(c, "You can't report yourself")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user"))
return
}
if data.UserID == 999 {
addMessage(c, errorMessage{T(c, "You can't report our bot ;3")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user"))
return
}
if data.UserID == 0 {
addMessage(c, errorMessage{T(c, "User not found")})
getSession(c).Save()
c.Redirect(302, "/")
return
}
defer resp(c, 200, "report.html", data)
data.TitleBar = T(c, "Report %s", username)
data.DisableHH = true
}
func reportSubmit(c *gin.Context) {
var (
userID int
username string
privileges uint64
)
if getContext(c).User.ID == 0 {
resp403(c)
return
}
ctx := getContext(c)
u := c.Param("user")
if _, err := strconv.Atoi(u); err != nil {
err := db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1", u).Scan(&userID, &username, &privileges)
if err != nil && err != sql.ErrNoRows {
c.Error(err)
}
} else {
err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
switch {
case err == nil:
case err == sql.ErrNoRows:
err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
if err != nil && err != sql.ErrNoRows {
c.Error(err)
}
default:
c.Error(err)
}
}
data := new(profileData)
data.UserID = userID
if data.UserID == getContext(c).User.ID {
addMessage(c, errorMessage{T(c, "You can't report yourself")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user"))
return
}
if data.UserID == 999 {
addMessage(c, errorMessage{T(c, "You can't report our bot ;3")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user"))
return
}
if data.UserID == 0 {
addMessage(c, errorMessage{T(c, "User not found")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user")+"/report")
return
}
reason, err := strconv.Atoi(c.PostForm("reason"))
if err != nil {
c.Error(err)
}
currentTime := int(time.Now().Unix())
reasonStr := ""
switch reason {
case 1:
reasonStr = "Foul play / Cheating"
break
case 2:
reasonStr = "Spamming"
break
case 3:
reasonStr = "Other"
break
default:
addMessage(c, errorMessage{T(c, "Not correct reason")})
c.Redirect(302, "/u/"+c.Param("user")+"/report")
return
}
_, err1 := db.Exec(`INSERT INTO reports (id, from_uid, to_uid, chatlog, reason, time, assigned) VALUES (NULL, ?, ?, ?, ?, ?, '');`,
getContext(c).User.ID, c.Param("user"), c.PostForm("addition"), reasonStr, currentTime)
if err1 != nil {
c.Error(err)
return
}
addMessage(c, successMessage{T(c, "User has been reported.")})
getSession(c).Save()
c.Redirect(302, "/u/"+c.Param("user"))
}