2024-07-13 13:58:36 +02:00
|
|
|
package frontend
|
2024-03-03 13:56:49 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
|
2024-07-13 14:09:11 +02:00
|
|
|
b "streifling.com/jason/cpolis/cmd/backend"
|
2024-03-03 13:56:49 +01:00
|
|
|
)
|
|
|
|
|
2024-07-13 14:09:11 +02:00
|
|
|
func CreateTag(c *b.Config) http.HandlerFunc {
|
2024-03-29 09:07:17 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-07-13 14:09:11 +02: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 {
|
2024-03-29 09:07:17 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:07:17 +01:00
|
|
|
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"])
|
|
|
|
}
|
|
|
|
}
|