diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 65a2993..5653ef2 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -52,7 +52,11 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -120,7 +124,11 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -179,7 +187,11 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -217,7 +229,11 @@ func ShowUnpublishedUnrejectedAndPublishedRejectedArticles(c *b.Config, db *b.DB } tmpl, err := template.ParseFiles(c.WebDir + "/templates/unpublished-articles.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -249,7 +265,11 @@ func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerF tmpl, err := template.ParseFiles(c.WebDir + "/templates/rejected-articles.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", data) + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -305,7 +325,11 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", data) + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -390,7 +414,11 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -416,7 +444,11 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -434,7 +466,11 @@ func ShowCurrentArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFu } tmpl, err := template.ParseFiles(c.WebDir + "/templates/current-articles.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -492,7 +528,11 @@ func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore, action strin tmpl, err := template.ParseFiles(c.WebDir + "/templates/published-articles.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", data) + if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -563,7 +603,11 @@ func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, butto } tmpl, err := template.ParseFiles(c.WebDir + "/templates/review-article.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -607,7 +651,11 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -659,7 +707,11 @@ func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -714,6 +766,10 @@ func EditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { data.Action = fmt.Sprint("save/", data.Article.ID) tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } diff --git a/cmd/frontend/issues.go b/cmd/frontend/issues.go index 58aaf5b..2ae6cbd 100644 --- a/cmd/frontend/issues.go +++ b/cmd/frontend/issues.go @@ -132,7 +132,11 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index 6cdad3f..e204a76 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -33,13 +33,17 @@ func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.Cookie tmpSession, err := s.Get(r, "cookie") if err != nil { - template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg) - return nil, err + if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg); err != nil { + return nil, fmt.Errorf("error executing template: %v", err) + } + return nil, fmt.Errorf("error getting session: %v", err) } session := &b.Session{Session: *tmpSession} if session.IsNew { - template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg) + if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg); err != nil { + return nil, fmt.Errorf("error executing template: %v", err) + } } return session, nil @@ -57,17 +61,29 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { if numRows == 0 { files[1] = c.WebDir + "/templates/first-user.html" tmpl, err := template.ParseFiles(files...) - template.Must(tmpl, err).Execute(w, nil) + if err = template.Must(tmpl, err).Execute(w, nil); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } else { session, _ := s.Get(r, "cookie") if auth, ok := session.Values["authenticated"].(bool); auth && ok { files[1] = c.WebDir + "/templates/hub.html" tmpl, err := template.ParseFiles(files...) - template.Must(tmpl, err).Execute(w, session.Values["role"]) + if err = template.Must(tmpl, err).Execute(w, session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } else { files[1] = c.WebDir + "/templates/login.html" tmpl, err := template.ParseFiles(files...) - template.Must(tmpl, err).Execute(w, nil) + if err = template.Must(tmpl, err).Execute(w, nil); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } } @@ -104,7 +120,11 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -123,7 +143,11 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -142,6 +166,10 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } diff --git a/cmd/frontend/editor.go b/cmd/frontend/tags.go similarity index 65% rename from cmd/frontend/editor.go rename to cmd/frontend/tags.go index f133e62..d3ad6a6 100644 --- a/cmd/frontend/editor.go +++ b/cmd/frontend/tags.go @@ -2,6 +2,7 @@ package frontend import ( "html/template" + "log" "net/http" b "streifling.com/jason/cpolis/cmd/backend" @@ -14,7 +15,11 @@ func CreateTag(c *b.Config, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-tag.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -29,6 +34,10 @@ func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } diff --git a/cmd/frontend/users.go b/cmd/frontend/users.go index fc38db4..fba214f 100644 --- a/cmd/frontend/users.go +++ b/cmd/frontend/users.go @@ -37,7 +37,11 @@ func CreateUser(c *b.Config, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -70,7 +74,11 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { len(htmlData.LastName) == 0 || len(pass) == 0 || len(pass2) == 0 { htmlData.Msg = "Alle Felder müssen ausgefüllt werden." tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } userString, stringLen, ok := checkUserStrings(htmlData.User) @@ -78,7 +86,11 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { htmlData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } id, _ := db.GetID(htmlData.UserName) @@ -86,13 +98,21 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { htmlData.Msg = fmt.Sprint(htmlData.UserName, " ist bereits vergeben. Bitte anderen Benutzernamen wählen.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } if pass != pass2 { htmlData.Msg = "Die Passwörter stimmen nicht überein." tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -105,7 +125,11 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -124,7 +148,11 @@ func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-self.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -152,7 +180,11 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { userData.Msg = "Alle Felder mit * müssen ausgefüllt sein." tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData.Msg) + if err = tmpl.ExecuteTemplate(w, "page-content", userData.Msg); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -162,7 +194,11 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { stringLen, " Zeichen erlaubt.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData) + if err = tmpl.ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -172,7 +208,11 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { userData.UserName = "" tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData) + if err = tmpl.ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } } @@ -187,12 +227,20 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { newPass2); err != nil { userData.Msg = "Aktualisierung der Benutzerdaten fehlgeschlagen." tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", userData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -214,7 +262,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { len(htmlData.LastName) == 0 || len(pass) == 0 || len(pass2) == 0 { htmlData.Msg = "Alle Felder müssen ausgefüllt werden." tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } userString, stringLen, ok := checkUserStrings(htmlData.User) @@ -222,7 +274,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { htmlData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } id, _ := db.GetID(htmlData.UserName) @@ -230,13 +286,21 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { htmlData.Msg = fmt.Sprint(htmlData.UserName, " ist bereits vergeben. Bitte anderen Benutzernamen wählen.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } if pass != pass2 { htmlData.Msg = "Die Passwörter stimmen nicht überein." tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -266,7 +330,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -292,7 +360,11 @@ func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.H delete(data.Users, session.Values["id"].(int64)) tmpl, err := template.ParseFiles(c.WebDir + "/templates/show-all-users.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -317,7 +389,11 @@ func EditUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { } tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -359,7 +435,11 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { userData.Msg = "Alle Felder mit * müssen ausgefüllt sein." tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData.Msg) + if err = tmpl.ExecuteTemplate(w, "page-content", userData.Msg); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -369,7 +449,11 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { stringLen, " Zeichen erlaubt.") tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData) + if err = tmpl.ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -379,7 +463,11 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { userData.UserName = "" tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", userData) + if err = tmpl.ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } } @@ -394,12 +482,20 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { userData.Role); err != nil { userData.Msg = "Aktualisierung der Benutzerdaten fehlgeschlagen." tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", userData) + if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", userData); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } } @@ -425,6 +521,10 @@ func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)) + if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } }