@@ -34,7 +34,7 @@ type Blog struct {
34
34
fb * formbuilder.FormBuilder
35
35
c * cookiestore.CookieStore
36
36
ia * goindieauth.IndieAuth
37
- li * LoginInfo
37
+ profile * Profile
38
38
wm * webmention.WebMention
39
39
gp * gopub.GoPub
40
40
}
@@ -48,20 +48,31 @@ var (
48
48
Port = flag .Int ("Port" , 3000 , "Specifies the port to listen on" )
49
49
)
50
50
51
+ type Profile struct {
52
+ Name string
53
+ Password string
54
+ Host string
55
+ Github string
56
+ }
57
+
51
58
func main () {
52
59
flag .Parse ()
60
+
53
61
theme , _ := tartheme .LoadDir ("theme" )
54
62
db , _ := bolt .Open ("blog.db" , 0666 , nil )
55
63
56
64
db .Update (func (tx * bolt.Tx ) error {
57
65
tx .CreateBucketIfNotExists ([]byte ("config" ))
58
66
tx .CreateBucketIfNotExists ([]byte ("posts" ))
59
67
tx .CreateBucketIfNotExists ([]byte ("subs" ))
60
-
61
68
return nil
62
69
})
63
70
64
71
blog := & Blog {}
72
+
73
+ data , _ := ioutil .ReadFile ("profile.json" )
74
+ json .Unmarshal (data , & blog .profile )
75
+
65
76
blog .templates = theme .Prefix ("templates/" ).AddTemplates (template .New ("default" ).Funcs (template.FuncMap {
66
77
"Route" : blog .Route ,
67
78
"AbsRoute" : blog .AbsRoute ,
@@ -75,7 +86,7 @@ func main() {
75
86
"SafeHTML" : SafeHTML ,
76
87
}))
77
88
mainrouter := mux .NewRouter ()
78
- blog .router = mainrouter .Host ("vendaria.net" ).Subrouter ()
89
+ blog .router = mainrouter .Host (blog . profile . Host ).Subrouter ()
79
90
blog .db = db
80
91
81
92
blog .fb = formbuilder .New (theme .Prefix ("templates/form/" ).Templates ())
@@ -124,9 +135,6 @@ func main() {
124
135
125
136
blog .gp .Hub , _ = pubhubroute .URL ()
126
137
127
- data , _ := ioutil .ReadFile ("login.json" )
128
- json .Unmarshal (data , & blog .li )
129
-
130
138
http .ListenAndServe (fmt .Sprintf (":%d" , * Port ), blog .router )
131
139
}
132
140
@@ -247,13 +255,6 @@ func (b *Blog) Post(rw http.ResponseWriter, req *http.Request) {
247
255
}
248
256
249
257
func (b * Blog ) AdminProfile (rw http.ResponseWriter , req * http.Request ) {
250
- var profile * Profile
251
-
252
- b .db .View (func (tx * bolt.Tx ) error {
253
- profiledata := tx .Bucket ([]byte ("config" )).Get ([]byte ("Profile" ))
254
- json .Unmarshal (profiledata , profile )
255
- return nil
256
- })
257
258
profileform := b .fb .GetForm ("profile" )
258
259
data := struct {
259
260
Name string
@@ -262,7 +263,7 @@ func (b *Blog) AdminProfile(rw http.ResponseWriter, req *http.Request) {
262
263
}{
263
264
"Profile" ,
264
265
"Profile" ,
265
- profileform .Render (nil , UrlToPath (b .router .Get ("AdminProfilePost" ).URL ()), "POST" ),
266
+ profileform .Render (b . profile , UrlToPath (b .router .Get ("AdminProfilePost" ).URL ()), "POST" ),
266
267
}
267
268
if err := b .templates .ExecuteTemplate (rw , "form.tpl" , data ); err != nil {
268
269
fmt .Println (err )
@@ -271,14 +272,9 @@ func (b *Blog) AdminProfile(rw http.ResponseWriter, req *http.Request) {
271
272
272
273
func (b * Blog ) AdminProfilePost (rw http.ResponseWriter , req * http.Request ) {
273
274
form := b .fb .GetForm ("profile" )
274
- data := & Profile {}
275
- form .Parse (req .FormValue , data )
276
- b .db .Update (func (tx * bolt.Tx ) error {
277
- config := tx .Bucket ([]byte ("config" ))
278
- jsondata , _ := json .Marshal (data )
279
- config .Put ([]byte ("Profile" ), jsondata )
280
- return nil
281
- })
275
+ form .Parse (req .FormValue , & b .profile )
276
+ data , _ := json .Marshal (b .profile )
277
+ ioutil .WriteFile ("profile.json" , data , 0600 )
282
278
http .Redirect (rw , req , UrlToPath (b .router .Get ("AdminProfile" ).URL ()), http .StatusSeeOther )
283
279
}
284
280
@@ -314,8 +310,8 @@ func (b *Blog) IACheckLogin(rw http.ResponseWriter, req *http.Request, user, pas
314
310
s := b .c .GetSession (req )
315
311
_ , ok := s .Values ["user" ]
316
312
s .Save (rw )
317
- if user == b .li . Me && (ok || password == b .li .Password ) {
318
- s .Values ["user" ] = b .li . Me
313
+ if user == b .AbsRoute ( "Home" ) && (ok || password == b .profile .Password ) {
314
+ s .Values ["user" ] = b .AbsRoute ( "Home" )
319
315
return true
320
316
}
321
317
return false
0 commit comments