Skip to content

Commit 29c1b13

Browse files
author
zainhoda
committed
Main page
1 parent 59888a7 commit 29c1b13

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math/rand"
99
"net/http"
1010
"os/exec"
11+
"regexp"
1112
"strconv"
1213
"time"
1314

@@ -55,7 +56,7 @@ func init() {
5556
return nil
5657
})
5758
db.Update(func(tx *bolt.Tx) error {
58-
_, err := tx.CreateBucketIfNotExists([]byte("UserToBlog")) // random string -> email
59+
_, err := tx.CreateBucketIfNotExists([]byte("UserToBlog")) // user -> blogdetails
5960
if err != nil {
6061
return fmt.Errorf("Error with UserToBlog: %s", err)
6162
}
@@ -114,6 +115,17 @@ func MainPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
114115
})
115116
}
116117

118+
func ErrorPage(w http.ResponseWriter, r *http.Request, pm httprouter.Params) {
119+
baseT := template.Must(template.New("base").Parse(base))
120+
baseT = template.Must(baseT.Parse(errorPage))
121+
122+
baseT.ExecuteTemplate(w, "base", map[string]string{
123+
"PageName": "error",
124+
"User": getUser(w, r),
125+
"Error": pm.ByName("errorcode"),
126+
})
127+
}
128+
117129
func SignupPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
118130
baseT := template.Must(template.New("base").Parse(base))
119131
baseT = template.Must(baseT.Parse(signup))
@@ -180,6 +192,10 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
180192
blogname := r.FormValue("blogname")
181193
website := r.FormValue("website")
182194
port := rand.Intn(63000) + 2000
195+
196+
re := regexp.MustCompile("[^A-Za-z]")
197+
blogname = re.ReplaceAllString(blogname, "")
198+
183199
blogcheck := []byte("")
184200

185201
username := getUser(w, r)
@@ -194,6 +210,7 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
194210
blogcheck = b.Get([]byte(blogname))
195211
return nil
196212
})
213+
197214
if blogcheck == nil {
198215
create, err := exec.Command("./create.sh", blogname, website, strconv.Itoa(port)).Output()
199216
if err != nil && !DEBUG {
@@ -376,5 +393,6 @@ func main() {
376393
router.GET("/admin/", AdminPage)
377394
router.POST("/admin/", AdminHandler)
378395
router.GET("/logout/", LogoutHandler)
396+
router.GET("/error/:errorcode/", ErrorPage)
379397
log.Fatal(http.ListenAndServe(":1337", router))
380398
}

pages.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var base = `
1212
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
1313
1414
<!-- Optional theme -->
15-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
15+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/paper/bootstrap.min.css">
1616
1717
<!-- Latest compiled and minified JavaScript -->
1818
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
@@ -210,8 +210,53 @@ var signup = `
210210
{{end}}
211211
`
212212

213+
var errorPage = `
214+
{{define "content"}}
215+
216+
<div class="col-md-6 col-md-offset-3">
217+
<div class="alert alert-danger" role="alert">
218+
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
219+
<span class="sr-only">Error:</span>
220+
{{.Error}}
221+
</div>
222+
</div>
223+
224+
{{end}}
225+
`
226+
213227
var mainPage = `
214228
{{define "content"}}
215-
Main
229+
230+
<div class="row">
231+
<div class="col-md-5 col-md-offset-1">
232+
<h1>GoBlog</h1>
233+
<h2>Simple Free Blog Hosting</h2>
234+
<hr>
235+
<h3>Deploy your own blog in as little as 15 seconds</h3>
236+
</div>
237+
<div class="col-md-6">
238+
<img src="https://placeholdit.imgix.net/~text?txtsize=100&txt=Animated%20GIF%20goes%20here&w=600&h=500" style="width:100%">
239+
</div>
240+
</div>
241+
242+
<hr>
243+
244+
<div class="row text-center">
245+
<h2>Simple to Set Up</h2>
246+
<div class="col-md-4">
247+
<h3>Easy to Deploy</h3>
248+
<i class="glyphicon glyphicon-ok" style="font-size: 20vw; color: #2196f3"></i>
249+
</div>
250+
<div class="col-md-4">
251+
<h3>Upload a Custom Theme</h3>
252+
<i class="glyphicon glyphicon-cloud-upload" style="font-size: 20vw; color: #2196f3"></i>
253+
</div>
254+
<div class="col-md-4">
255+
<h3>Use Your Own Domain Name</h3>
256+
<i class="glyphicon glyphicon-globe" style="font-size: 20vw; color: #2196f3"></i>
257+
</div>
258+
259+
</div>
260+
216261
{{end}}
217262
`

0 commit comments

Comments
 (0)