diff --git a/cmd/backend/atom.go b/cmd/backend/atom.go index 832f567..f289aaa 100644 --- a/cmd/backend/atom.go +++ b/cmd/backend/atom.go @@ -18,7 +18,7 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { feed.Generator = atom.NewGenerator("cpolis") feed.Generator.URI = "https://git.streifling.com/jason/cpolis" - feed.Generator.Version = "0.13" + feed.Generator.Version = c.Version articles, err := db.GetCertainArticles("published", true) if err != nil { diff --git a/cmd/backend/config.go b/cmd/backend/config.go index fd2e056..7ba995f 100644 --- a/cmd/backend/config.go +++ b/cmd/backend/config.go @@ -27,6 +27,7 @@ type Config struct { PicsDir string Port string Title string + Version string WebDir string MaxImgHeight int MaxImgWidth int @@ -47,6 +48,7 @@ func newConfig() *Config { PDFDir: "/var/www/cpolis/pdfs", PicsDir: "/var/www/cpolis/pics", Port: ":8080", + Version: "v0.13.0", WebDir: "/var/www/cpolis/web", } } diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 5cdaa89..58cb481 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -146,9 +146,12 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -225,9 +228,12 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -469,9 +475,12 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -501,9 +510,12 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -698,9 +710,12 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -755,8 +770,11 @@ func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl := template.Must(template.ParseFiles(c.WebDir + "/templates/hub.html")) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/issues.go b/cmd/frontend/issues.go index ec0c6d6..efa1ba8 100644 --- a/cmd/frontend/issues.go +++ b/cmd/frontend/issues.go @@ -110,9 +110,12 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index 8320dcc..cb2e99f 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -56,12 +56,18 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { log.Fatalln(err) } + data := new(struct { + Version string + Role int + }) + data.Version = c.Version + files := make([]string, 2) files[0] = c.WebDir + "/templates/index.html" if numRows == 0 { files[1] = c.WebDir + "/templates/first-user.html" tmpl, err := template.ParseFiles(files...) - if err = template.Must(tmpl, err).Execute(w, nil); err != nil { + if err = template.Must(tmpl, err).Execute(w, data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -74,9 +80,10 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } if auth, ok := session.Values["authenticated"].(bool); auth && ok { + data.Role = session.Values["role"].(int) files[1] = c.WebDir + "/templates/hub.html" tmpl, err := template.ParseFiles(files...) - if err = template.Must(tmpl, err).Execute(w, session.Values["role"]); err != nil { + if err = template.Must(tmpl, err).Execute(w, data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -84,7 +91,7 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } else { files[1] = c.WebDir + "/templates/login.html" tmpl, err := template.ParseFiles(files...) - if err = template.Must(tmpl, err).Execute(w, nil); err != nil { + if err = template.Must(tmpl, err).Execute(w, data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -125,7 +132,7 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role); err != nil { + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -174,8 +181,11 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/tags.go b/cmd/frontend/tags.go index 164228e..9b92729 100644 --- a/cmd/frontend/tags.go +++ b/cmd/frontend/tags.go @@ -41,9 +41,12 @@ func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } db.AddTag(tag) + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/users.go b/cmd/frontend/users.go index 8d12a70..a2aa4d7 100644 --- a/cmd/frontend/users.go +++ b/cmd/frontend/users.go @@ -101,9 +101,12 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -183,9 +186,12 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -245,8 +251,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = 0 + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0); err != nil { + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -374,8 +383,11 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl := template.Must(template.ParseFiles(c.WebDir + "/templates/hub.html")) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -405,9 +417,12 @@ func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } + data := new(struct{ Role int }) + data.Role = session.Values["role"].(int) + tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/web/templates/hub.html b/web/templates/hub.html index 0c49698..39803b1 100644 --- a/web/templates/hub.html +++ b/web/templates/hub.html @@ -2,30 +2,31 @@