cpolis/cmd/ui/editor.go

31 lines
862 B
Go
Raw Normal View History

2024-03-03 13:56:49 +01:00
package ui
import (
"html/template"
"net/http"
"streifling.com/jason/cpolis/cmd/data"
)
func CreateTag(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("web/templates/add-tag.html")
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
}
2024-03-06 20:53:17 +01:00
func AddTag(db *data.DB, s *data.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("web/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("web/templates/hub.html")
tmpl = template.Must(tmpl, err)
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
}
}