8
8
"math/rand"
9
9
"net/http"
10
10
"os/exec"
11
+ "regexp"
11
12
"strconv"
12
13
"time"
13
14
@@ -55,7 +56,7 @@ func init() {
55
56
return nil
56
57
})
57
58
db .Update (func (tx * bolt.Tx ) error {
58
- _ , err := tx .CreateBucketIfNotExists ([]byte ("UserToBlog" )) // random string -> email
59
+ _ , err := tx .CreateBucketIfNotExists ([]byte ("UserToBlog" )) // user -> blogdetails
59
60
if err != nil {
60
61
return fmt .Errorf ("Error with UserToBlog: %s" , err )
61
62
}
@@ -114,6 +115,17 @@ func MainPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
114
115
})
115
116
}
116
117
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
+
117
129
func SignupPage (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
118
130
baseT := template .Must (template .New ("base" ).Parse (base ))
119
131
baseT = template .Must (baseT .Parse (signup ))
@@ -180,6 +192,10 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
180
192
blogname := r .FormValue ("blogname" )
181
193
website := r .FormValue ("website" )
182
194
port := rand .Intn (63000 ) + 2000
195
+
196
+ re := regexp .MustCompile ("[^A-Za-z]" )
197
+ blogname = re .ReplaceAllString (blogname , "" )
198
+
183
199
blogcheck := []byte ("" )
184
200
185
201
username := getUser (w , r )
@@ -194,6 +210,7 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
194
210
blogcheck = b .Get ([]byte (blogname ))
195
211
return nil
196
212
})
213
+
197
214
if blogcheck == nil {
198
215
create , err := exec .Command ("./create.sh" , blogname , website , strconv .Itoa (port )).Output ()
199
216
if err != nil && ! DEBUG {
@@ -376,5 +393,6 @@ func main() {
376
393
router .GET ("/admin/" , AdminPage )
377
394
router .POST ("/admin/" , AdminHandler )
378
395
router .GET ("/logout/" , LogoutHandler )
396
+ router .GET ("/error/:errorcode/" , ErrorPage )
379
397
log .Fatal (http .ListenAndServe (":1337" , router ))
380
398
}
0 commit comments