-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
executable file
·150 lines (122 loc) · 3.58 KB
/
handlers.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
package main
import (
"html/template"
"net/http"
"sort"
"strings"
"github.com/go-macaron/csrf"
"gopkg.in/macaron.v1"
)
func homeHandler(ctx *macaron.Context, x csrf.CSRF) {
ctx.Data["Title"] = "Home"
ctx.Data["csrf_token"] = x.GetToken()
ctx.HTML(http.StatusOK, "index")
}
func homeHandlerPOST(ctx *macaron.Context, form contactForm) {
form.Name = ctx.Query("name")
form.Description = ctx.Query("description")
if form.Name == "" {
form.Name = "[NO NAME PROVIDED]"
}
form.Description = "Message From: " + form.Name + "\n\n" + "Description: " + form.Description
sendMail("Message From: "+form.Name, form.Description, ctx)
}
func projectsHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Projects"
sort.Sort(byDate(projectsArr))
ctx.Data["Projects"] = projectsArr
ctx.HTML(http.StatusOK, "projects")
}
func projectsFileHandler(ctx *macaron.Context) {
name := ctx.Params("name")
getPosts("public/projects/")
postFound := false
for _, post := range projectsArr {
if post.FileName == name {
ctx.Data["HTML"] = template.HTML(post.HTML)
ctx.Data["Name"] = post.FileName
ctx.Data["ColourLight"] = post.ColourLight
ctx.Data["ColourDark"] = post.ColourDark
ctx.Data["Title"] = strings.Title(post.FileName)
ctx.Data["ProjDesc"] = post.Description
postFound = true
}
}
if postFound {
ctx.HTML(http.StatusOK, "post")
} else {
ctx.Data["Title"] = "Not Found"
ctx.HTML(http.StatusNotFound, "404")
}
}
func blogHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Blog"
sort.Sort(byDate(blogsArr))
ctx.Data["Blog"] = blogsArr
ctx.HTML(http.StatusOK, "blog")
}
func blogFileHandler(ctx *macaron.Context) {
name := ctx.Params("name")
postFound := false
for _, post := range blogsArr {
if post.FileName == name {
ctx.Data["HTML"] = template.HTML(post.HTML)
ctx.Data["Name"] = post.FileName
ctx.Data["ColourLight"] = post.ColourLight
ctx.Data["ColourDark"] = post.ColourDark
ctx.Data["Title"] = strings.Title(post.FileName)
ctx.Data["BlogDesc"] = post.Description
postFound = true
}
}
if postFound {
ctx.HTML(http.StatusOK, "post")
} else {
ctx.Data["Title"] = "Not Found"
ctx.HTML(http.StatusNotFound, "404")
}
}
func picsHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Pictures"
ctx.HTML(http.StatusOK, "pics")
}
func reportHandler(ctx *macaron.Context, x csrf.CSRF) {
ctx.Data["Title"] = "Report Issue"
ctx.Data["csrf_token"] = x.GetToken()
ctx.HTML(http.StatusOK, "report")
}
func reportHandlerPOST(ctx *macaron.Context, form reportForm) {
form.Category = "Website Report: " + ctx.Query("category")
form.Email = ctx.Query("email")
form.Description = ctx.Query("description")
if form.Email == "" {
form.Email = "[NO EMAIL PROVIDED]"
}
form.Description = "Category: " + form.Category + "\n\n" + "Email: " + form.Email + "\n\n" + "Description: " + form.Description
sendMail(form.Category, form.Description, ctx)
}
func thankyouHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Thank You"
ctx.HTML(http.StatusOK, "thankyou")
}
func emailerrorHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Report Error"
ctx.HTML(http.StatusOK, "emailerror")
}
func creditsHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Credits"
ctx.HTML(http.StatusOK, "credits")
}
func linksHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Links"
ctx.Data["Links"] = linksArr
ctx.HTML(http.StatusOK, "links")
}
func trafficHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Traffic"
ctx.HTML(http.StatusOK, "traffic")
}
func alakbotHandler(ctx *macaron.Context) {
ctx.Data["Title"] = "Alakbot"
ctx.HTML(http.StatusOK, "alakbot")
}