cpolis/cmd/view/editor.go

34 lines
1013 B
Go
Raw Normal View History

2024-03-09 10:25:20 +01:00
package view
2024-03-03 13:56:49 +01:00
import (
"html/template"
"net/http"
2024-03-09 10:25:20 +01:00
"streifling.com/jason/cpolis/cmd/control"
"streifling.com/jason/cpolis/cmd/model"
2024-03-03 13:56:49 +01:00
)
func CreateTag(c *control.CliArgs) 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 *control.CliArgs, db *model.DB, s *control.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"])
}
}