cpolis/cmd/frontend/editor.go

33 lines
954 B
Go
Raw Normal View History

package frontend
2024-03-03 13:56:49 +01:00
import (
"html/template"
"net/http"
b "streifling.com/jason/cpolis/cmd/backend"
2024-03-03 13:56:49 +01:00
)
func CreateTag(c *b.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-tag.html")
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
}
2024-03-03 13:56:49 +01:00
}
func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
2024-03-03 13:56:49 +01:00
return func(w http.ResponseWriter, r *http.Request) {
2024-03-06 20:53:17 +01:00
db.AddTag(r.PostFormValue("tag"))
2024-03-03 13:56:49 +01:00
session, err := s.Get(r, "cookie")
if err != nil {
tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html")
2024-03-03 13:56:49 +01:00
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")
2024-03-03 13:56:49 +01:00
tmpl = template.Must(tmpl, err)
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
}
}