forked from osuthailand/hanayo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.go
executable file
·51 lines (48 loc) · 1.39 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
package main
import (
"database/sql"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
func reportUser(c *gin.Context) {
// Made by Simon
var (
allowedtoreport bool
)
user, err := strconv.ParseInt(c.PostForm("userid"), 10, 32)
if err != nil {
c.Error(err)
}
ctx := getContext(c)
if ctx.User.ID == 0 {
resp403(c)
return
}
err = db.QueryRow("SELECT allowedtoreport FROM users WHERE id = ? ", ctx.User.ID).Scan(&allowedtoreport)
if err != nil && err != sql.ErrNoRows {
c.Error(err)
}
if allowedtoreport {
text := c.PostForm("text")
if text == "" {
addMessage(c, errorMessage{T(c, "You need to give us some information!")})
} else {
reason := c.PostForm("reasons")
if reason == "" {
addMessage(c, errorMessage{T(c, "You need to tell us what the person has done!")})
} else {
_, err = db.Exec(`INSERT INTO reports(from_uid, to_uid, reason, chatlog, time) VALUES (?, ?, ?, ?, ?);`, ctx.User.ID, user, reason, text, time.Now().Unix())
if err != nil {
c.Error(err)
}
_, err = db.Exec(`INSERT INTO rap_logs(userid, text, datetime, through) VALUES(?, 'just reported someone, check the reports!', ?, 'Simon\'s epic reporting system!')`, ctx.User.ID, time.Now().Unix())
if err != nil {
c.Error(err)
}
}
}
} else {
addMessage(c, errorMessage{T(c, "Yeah, you can't do that man...")})
}
}