forked from osuripple/hanayo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.go
48 lines (37 loc) · 1.02 KB
/
oauth.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
package main
import (
"database/sql"
"github.com/gin-gonic/gin"
"zxq.co/ripple/hanayo/routers/oauth"
)
type oauthRequestHandler struct{}
func (o oauthRequestHandler) CheckLoggedInOrRedirect(c *gin.Context) bool {
ctx := getContext(c)
if ctx.User.ID == 0 {
resp403(c)
return false
}
return true
}
func (o oauthRequestHandler) DisplayAuthorizePage(client oauth.Client, c *gin.Context) {
var creatorName string
db.Get(&creatorName, "SELECT username FROM users WHERE id = ? LIMIT 1", client.CreatorID)
c.Header("X-Frame-Options", "deny")
simple(c, getSimpleByFilename("oauth.html"), nil, map[string]interface{}{
"Client": client,
"CreatorName": creatorName,
})
}
func (o oauthRequestHandler) CheckCSRF(c *gin.Context, s string) bool {
b, _ := CSRF.Validate(getContext(c).User.ID, s)
return b
}
func (o oauthRequestHandler) GetDB() *sql.DB {
return db.DB
}
func (o oauthRequestHandler) GetUserID(c *gin.Context) int {
return getContext(c).User.ID
}
func setUpOauth() {
oauth.Initialise(oauthRequestHandler{})
}