-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpages.go
93 lines (83 loc) · 2.28 KB
/
pages.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
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
const (
IsUserLinked = `SELECT EXISTS(SELECT 1 FROM users WHERE email = $1)`
GetWiiNumberUser = `SELECT wii_number FROM users WHERE email = $1`
GetLinkedDominos = `SELECT dominos_linked FROM users WHERE email = $1`
)
func HomePage(c *gin.Context) {
if username, ok := c.Get("username"); ok {
if email, ok := c.Get("email"); ok {
var exists bool
err := pool.QueryRow(ctx, IsUserLinked, email.(string)).Scan(&exists)
if err != nil {
c.HTML(http.StatusBadRequest, "error.html", gin.H{
"Error": err.Error(),
})
return
}
if exists {
log.Printf("User with username %s is linked!!!", username)
var wiiNumber string
var linked_dominos bool
err := pool.QueryRow(ctx, GetWiiNumberUser, email.(string)).Scan(&wiiNumber)
if err != nil {
c.HTML(http.StatusBadRequest, "error.html", gin.H{
"Error": err.Error(),
})
return
}
err = pool.QueryRow(ctx, GetLinkedDominos, email.(string)).Scan(&linked_dominos)
if err != nil {
c.HTML(http.StatusBadRequest, "error.html", gin.H{
"Error": err.Error(),
})
return
}
if pfp, ok := c.Get("picture"); ok {
c.HTML(http.StatusOK, "linked.html", gin.H{
"username": username,
"email": email,
"pfp": pfp,
"wiinumber": wiiNumber,
"linked_dominos": linked_dominos,
})
} else {
c.HTML(http.StatusOK, "linked.html", gin.H{
"username": username,
"email": email,
"wiinumber": wiiNumber,
"linked_dominos": linked_dominos,
})
}
} else {
log.Printf("User with username %s is not linked", username)
if pfp, ok := c.Get("picture"); ok {
c.HTML(http.StatusOK, "not_linked.html", gin.H{
"username": username,
"pfp": pfp,
})
} else {
c.HTML(http.StatusOK, "not_linked.html", gin.H{
"username": username,
})
}
}
return
}
}
c.HTML(http.StatusBadRequest, "error.html", gin.H{
"Error": "Username not found in context",
})
}
func NotLinkedPage(c *gin.Context) {
email, _ := c.Get("email")
log.Printf("User with email %s is not linked", email)
c.HTML(http.StatusOK, "not_linked.html", gin.H{
"email": email,
})
}