Change structure of code tor frontend and backend one

This commit is contained in:
2024-07-13 13:58:36 +02:00
parent 21fd3403b2
commit d0c1e525d2
18 changed files with 197 additions and 126 deletions

30
cmd/frontend/issues.go Normal file
View File

@ -0,0 +1,30 @@
package frontend
import (
"html/template"
"log"
"net/http"
"streifling.com/jason/cpolis/cmd/backend"
)
func PublishLatestIssue(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := db.PublishLatestIssue(); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
session, err := s.Get(r, "cookie")
if err != nil {
tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html")
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
}
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
tmpl = template.Must(tmpl, err)
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
}
}