forked from osuthailand/hanayo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
140 lines (122 loc) · 3.87 KB
/
profile.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
package main
import (
"database/sql"
"strconv"
"github.com/gin-gonic/gin"
"github.com/osuthailand/api/common"
)
// TODO: replace with simple ResponseInfo containing userid
type profileData struct {
baseTemplateData
UserID int
}
func userProfile(c *gin.Context) {
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)
}
}
if db.QueryRow("SELECT 1 FROM users_stats WHERE id = ? AND prefer_relax = 1", userID).
Scan(new(int)) != sql.ErrNoRows {
getSession(c).Save()
c.Redirect(302, "/rx/u/"+strconv.Itoa(userID))
return
}
data := new(profileData)
data.UserID = userID
defer resp(c, 200, "profile.html", data)
if data.UserID == 0 {
data.TitleBar = "User not found"
data.Messages = append(data.Messages, warningMessage{T(c, "That user could not be found.")})
return
}
if common.UserPrivileges(privileges)&common.UserPrivilegeDonor > 0 {
var profileBackground struct {
Type int
Value string
}
db.Get(&profileBackground, "SELECT type, value FROM profile_backgrounds WHERE uid = ?", data.UserID)
switch profileBackground.Type {
case 1:
data.KyutGrill = "/static/profbackgrounds/" + profileBackground.Value
data.KyutGrillAbsolute = true
case 2:
data.SolidColour = profileBackground.Value
}
}
data.TitleBar = T(c, "%s's profile", username)
data.DisableHH = true
data.Scripts = append(data.Scripts, "/static/profile.js")
}
func relaxProfile(c *gin.Context) {
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
defer resp(c, 200, "profile_rx.html", data)
if data.UserID == 0 {
data.TitleBar = "User not found"
data.Messages = append(data.Messages, warningMessage{T(c, "That user could not be found.")})
return
}
if common.UserPrivileges(privileges)&common.UserPrivilegeDonor > 0 {
var profileBackground struct {
Type int
Value string
}
db.Get(&profileBackground, "SELECT type, value FROM profile_backgrounds WHERE uid = ?", data.UserID)
switch profileBackground.Type {
case 1:
data.KyutGrill = "/static/profbackgrounds/" + profileBackground.Value
data.KyutGrillAbsolute = true
case 2:
data.SolidColour = profileBackground.Value
}
}
data.TitleBar = T(c, "%s's profile", username)
data.DisableHH = true
data.Scripts = append(data.Scripts, "/static/rxprofile.js")
}