Just a bit of cleaning up
This commit is contained in:
parent
2da17014e4
commit
8f7ac979a3
@ -9,10 +9,10 @@ const (
|
||||
type Role int
|
||||
|
||||
type User struct {
|
||||
RejectedArticles *ArticleList
|
||||
UserName string
|
||||
FirstName string
|
||||
LastName string
|
||||
RejectedArticles []*Article
|
||||
ID int64
|
||||
Role
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type AddUserData struct {
|
||||
data.User
|
||||
Msg string
|
||||
data.User
|
||||
}
|
||||
|
||||
func inputsEmpty(user data.User, pass, pass2 string) bool {
|
||||
@ -46,16 +46,27 @@ func HomePage(db *data.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
if numRows == 0 {
|
||||
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/add-user.html")).Execute(w, nil)
|
||||
files := []string{
|
||||
"web/templates/index.html",
|
||||
"web/templates/add-user.html",
|
||||
}
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
template.Must(tmpl, err).Execute(w, nil)
|
||||
} else {
|
||||
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/login.html")).Execute(w, nil)
|
||||
files := []string{
|
||||
"web/templates/index.html",
|
||||
"web/templates/login.html",
|
||||
}
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
template.Must(tmpl, err).Execute(w, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CreateUser() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,24 +92,30 @@ func AddUser(db *data.DB) http.HandlerFunc {
|
||||
|
||||
if inputsEmpty(htmlData.User, pass, pass2) {
|
||||
htmlData.Msg = "Alle Felder müssen ausgefüllt werden."
|
||||
template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", htmlData)
|
||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
||||
return
|
||||
}
|
||||
userString, stringLen, ok := checkUserStrings(htmlData.User)
|
||||
if !ok {
|
||||
htmlData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt.")
|
||||
template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", htmlData)
|
||||
htmlData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ",
|
||||
stringLen, " Zeichen erlaubt.")
|
||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
||||
return
|
||||
}
|
||||
id, _ := db.GetID(htmlData.UserName)
|
||||
if id != 0 {
|
||||
htmlData.Msg = fmt.Sprint(htmlData.UserName, " ist bereits vergeben. Bitte anderen Benutzernamen wählen.")
|
||||
template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", htmlData)
|
||||
htmlData.Msg = fmt.Sprint(htmlData.UserName,
|
||||
" ist bereits vergeben. Bitte anderen Benutzernamen wählen.")
|
||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
||||
return
|
||||
}
|
||||
if pass != pass2 {
|
||||
htmlData.Msg = "Die Passwörter stimmen nicht überein."
|
||||
template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", htmlData)
|
||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
||||
return
|
||||
}
|
||||
|
||||
@ -107,6 +124,7 @@ func AddUser(db *data.DB) http.HandlerFunc {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,15 @@ import (
|
||||
|
||||
func ShowHub() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteArticle() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/editor.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,13 +56,15 @@ func FinishArticle(l *data.ArticleList) http.HandlerFunc {
|
||||
|
||||
l.Add(article)
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func ShowUnpublishedArticles(l *data.ArticleList) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/unpublished-articles.html")).ExecuteTemplate(w, "page-content", l.Get())
|
||||
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", l.Get())
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,11 +79,13 @@ func ReviewArticle(l *data.ArticleList) http.HandlerFunc {
|
||||
|
||||
for _, article := range l.Get() {
|
||||
if article.UUID == uuid {
|
||||
template.Must(template.ParseFiles("web/templates/to-be-published.html")).ExecuteTemplate(w, "page-content", article)
|
||||
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", article)
|
||||
return
|
||||
}
|
||||
}
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +102,8 @@ func PublishArticle(f *data.Feed, l *data.ArticleList) http.HandlerFunc {
|
||||
if !ok {
|
||||
// TODO: Warnung anzeigen
|
||||
// msg = "Alle Felder müssen ausgefüllt werden."
|
||||
// template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", msg)
|
||||
// tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
||||
// template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||
return
|
||||
}
|
||||
|
||||
@ -108,6 +115,7 @@ func PublishArticle(f *data.Feed, l *data.ArticleList) http.HandlerFunc {
|
||||
})
|
||||
f.Save("tmp/rss.gob")
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ func ShowRSS(f *data.Feed) http.HandlerFunc {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/feed.rss")).Execute(w, rss)
|
||||
|
||||
files := []string{"web/templates/index.html", "web/templates/feed.rss"}
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
template.Must(tmpl, err).Execute(w, rss)
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ func Login(db *data.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user